Jump to content

Undefined variable and Call to a member function on a non-object


raydona
 Share

Recommended Posts

Hello,
   I have the situation shown below in the code:
if(//condition is met)
{ $val = new Val();
  $valon = $val->check($_POST, array(.........));
}
if($valon->passes())
{ $use = new Use();
  ........
}
//check() and passes() both belong to class Val
public function check($source, $items = array())
{ ......................
  return $this;
}

I get the following warning and error:

Notice: Undefined variable: valon
and
Fatal error: Call to a member function passes() on a non-object

I can't see anything wrong with the code. check() returns an object of class Val which is assigned to $valon, $valon then calls a member function of class Val. Could you please help. Please let me know whether to include further code.

 

Link to comment
Share on other sites

Jacques1 is correct, but your second if statement could just go inside the first to solve that.

 

 

<?php

if ( /* true || false */ )
{
    $val   = new Val();
    $valon = $val -> check($_POST, array('a', 'b', 'c'));
    
    if ($valon -> passes())
    {
        $use = new Use();
        // ...
    }
}

?>
Link to comment
Share on other sites

This thread is more than a year old.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.