Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Fatal error: Call to undefined method stdClass

Tags:

php

mysql

class

I get an error that says

Fatal error: Call to undefined method stdClass::mysql_con() in ........../.../includes/script/import.php on line 68.

Line 68 corresponds to:

if(!$ip2c->mysql_con())

I do have a require_once() statement at the beginning of my script

What could be the problem here?

Thanks

like image 587
jojez Avatar asked Dec 14 '22 02:12

jojez


1 Answers

Dusoft says it could mean:

  • $ip2c object does not exist,

    Which is not correct because you would get a different error "Fatal error: Call to a member function mysql_con() on a non-object"

He also says it could mean:

  • mysql_con function is not part of the class you are trying to call

    Which is true but not so helpful cos its very difficult to add methods to stdClass.

Additionally it could be to do with serialisation quote:

  • This error is normally thrown when a class instance has been serialised to disk, then re-read/deserialised in another request but the class definition has not been loaded yet, so PHP creates it as an "stdClass" (standard class.)

Or most likely, I think:

  • the $ip2c variable was not an object and then php silently cast it to become stdClass somewhere in the code above.

    This could happen if you directly assign a property on it.

Like:

 $ip2c = null;
 
 //php casts $ip2c to 'stdClass'
 $ip2c->foo = bah;
 
 //Fatal error: Call to undefined method stdClass::mysql_con() in...
 $ip2c->mysql_con();

See a better example here.

like image 54
JW. Avatar answered Dec 25 '22 01:12

JW.