2

I am getting a warning in php while running my application

HTML code:

      <a href="cart.html" class="dropdown-toggle" data-toggle="dropdown"><span> <?php if($a==true) { ?><?php echo $d->n;  ?> <?php } ?></span></a>

PHP code:

      $q=$mysqli->query("select object from object_store where Email='$email' ");
      $r=$q->fetch_assoc();
      $d=unserialize($r['object']);
      if(!is_null($d))
      {
      $a=true;
      }
      else
      {
      $a=false;
      }

The warning is cant call a member function on non object. I know that at first the value of $d is NULL but having used $a variable for check still the code block of $d is getting executed. Please suggest a way to remove this warning.

4
  • Most likely the warning references a specific error number? I would guess that command: $q->fetch_assoc(); since it is the only line in your code that actually uses any object. Actually this is a pretty typical error that has been answered endless times before: you do not do any error checking or handling at all. you blindly trust that your query well succeed. Most likely it does not succeed, but the call returns a boolean false. You cannot call a method on a boolean value. Commented Nov 22, 2015 at 18:02
  • my default object value is null and the query is running correctly Commented Nov 22, 2015 at 18:06
  • What is a "default object value"? And what line is referenced in the error you get? Commented Nov 22, 2015 at 18:06
  • in the HTML code which encloses $a boolean value it is displaying the warning Commented Nov 22, 2015 at 18:08

1 Answer 1

1

I think this code:

$d=unserialize($r['object']);
if(!is_null($d))

will always be true, since unserialize doesn't return null.

Try: if($d != false) or if(is_array($d))

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.