Dismiss Notice
Join Physics Forums Today!
The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

PHP - Wrong datatype for second argument

  1. Jan 23, 2009 #1


    User Avatar

    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)...


    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...


                $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. jcsd
  3. Jan 24, 2009 #2


    User Avatar
    Science Advisor
    Homework Helper

    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?
  4. Jan 24, 2009 #3


    User Avatar

    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.
Know someone interested in this topic? Share this thread via Reddit, Google+, Twitter, or Facebook

Similar Discussions: PHP - Wrong datatype for second argument
  1. PHP Help ? (Replies: 16)

  2. Php or c++ ? (Replies: 40)

  3. PHP - limiting output (Replies: 7)