开发者

Fatal error: Call to undefined method stdClass

开发者 https://www.devze.com 2022-12-08 07:36 出处:网络
I get an error that says Fatal error: Call to undefined method stdClass::mysql_con() in ........../.../includes/script/import.php on line 68. 开发者_C百科

I get an error that says

Fatal error: Call to undefined method stdClass::mysql_con() in ........../.../includes/script/import.php on line 68. 开发者_C百科

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


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.


it means that either $ip2c object does not exist or mysql_con function is not part of the class you are trying to call.


I think this happen because "extension=php_mysql.dll" extension isn't loaded in php.ini. Take a look with

phpinfo();


It could be incorrect code. I once managed to get that error when I had this line of code:

if ($myObj->property_exists('min')){
    // do something
}

Which resulted in error line like this:

PHP Fatal error: Call to undefined method stdClass::property_exists() in myFile.php on line ###

I later fixed the line to:

if (property_exists($myObj, 'min')) {
    // do something
}

So check for that possibility as well.


Most likely the object does not exist. Please show us the code of how you created it. If you are using it within another class (maybe creating it in the __construct function for example), using:

$ip2c = new Class;

Won't cut it. Instead do:

$this->ip2c = new Class;

and then

$this->ip2c->mysql_con();
0

精彩评论

暂无评论...
验证码 换一张
取 消