# PHP - Wrong datatype for second argument

1. Jan 23, 2009

### jgg

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.

2. Jan 24, 2009

### CompuChip

Re: PHP - "Wrong datatype for second argument"

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?

3. Jan 24, 2009

### jgg

Re: PHP - "Wrong datatype for second argument"

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

I made it global and that worked for me.