PHP - Wrong datatype for second argument

  • Context: PHP 
  • Thread starter Thread starter jgg
  • Start date Start date
  • Tags Tags
    Argument Php
Join the discussion
Registration is free. Ask a follow-up in this thread, or start your own.
2 replies · 5K views
jgg
Messages
40
Reaction score
0
PHP - "Wrong datatype for second argument"

So I build this class in my library file (assume that I have all the PHP tags and stuff)...

PHP:
class errorchecker {

var $error;

function errorsearch($error) {

if (in_array($error, $pb)){
	echo '<div class="error">'.$error.'</div>';
	}
}

}

Where '$pb' is an array I have created, that gets assigned a new string given a certain set of conditions. Thus, I wanted to use this object to check for certain strings in an array, and if it's there print out another string.


Then on the main PHP page, I create an instance of the object and attempt to use it as such...

PHP:
<?php 
			$one = new errorchecker;		
			$one -> errorsearch('String I want to be searched for');
			?>


but it doesn't work, and I get slammed with

"Warning: in_array() [function.in-array]: Wrong datatype for second argument in directory on line xxxx"

Which points to my function errorsearch above. What am I doing wrong (it also does this if I just use a function)? This is my first time writing in PHP, so apologies if I missed something stupid.
 
Physics news on Phys.org


I solved my own problem shortly after posting this...

Try doing vardump($pb) inside the errorsearch function... is you array defined in there? Otherwise, do you maybe need to define it within your class or make it global inside the function?

I made it global and that worked for me.