php 致命错误:调用未定义的方法 stdClass
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/1568489/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Fatal error: Call to undefined method stdClass
提问by jojez
I get an error that says
我收到一个错误提示
Fatal error: Call to undefined method stdClass::mysql_con() in ........../.../includes/script/import.php on line 68.
致命错误:在 ../.../includes/script/import.php 中调用未定义的方法 stdClass::mysql_con() 第 68 行。
Line 68 corresponds to:
第 68 行对应于:
if(!$ip2c->mysql_con())
I do have a require_once()statement at the beginning of my script
我require_once()在脚本的开头确实有一个声明
What could be the problem here?
这里可能有什么问题?
Thanks
谢谢
回答by JW.
Dusoft saysit could mean:
Dusoft 说这可能意味着:
$ip2cobject does not exist,Which is notcorrect because you would get a different error "
Fatal error: Call to a member function mysql_con() on a non-object"
$ip2c对象不存在,这是不正确的,因为你会得到一个不同的错误“
Fatal error: Call to a member function mysql_con() on a non-object”
He also says it could mean:
他还说这可能意味着:
mysql_confunction is not part of the class you are trying to callWhich is true but not so helpful cos its very difficult to add methods to
stdClass.
mysql_con函数不是您尝试调用的类的一部分这是真的,但不是很有帮助,因为很难将方法添加到
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.)
- 当类实例已序列化到磁盘,然后在另一个请求中重新读取/反序列化但尚未加载类定义时,通常会抛出此错误,因此 PHP 将其创建为“stdClass”(标准类)。
Or most likely, I think:
或者最有可能,我认为:
the
$ip2cvariable 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.
该
$ip2c变量不是一个对象,然后 php 默默地将它转换为上面代码中某处的 stdClass 。如果您直接为其分配属性,则可能会发生这种情况。
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.
回答by dusoft
it means that either $ip2c object does not exist or mysql_con function is not part of the class you are trying to call.
这意味着 $ip2c 对象不存在或 mysql_con 函数不是您尝试调用的类的一部分。
回答by Ismael
I think this happen because "extension=php_mysql.dll" extension isn't loaded in php.ini. Take a look with
我认为这是因为“extension=php_mysql.dll”扩展没有加载到 php.ini 中。看看
phpinfo();
phpinfo();
回答by Bradley Slavik
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 ###
PHP 致命错误:在线 ### 上调用 myFile.php 中未定义的方法 stdClass::property_exists()
I later fixed the line to:
我后来将这条线固定为:
if (property_exists($myObj, 'min')) {
// do something
}
So check for that possibility as well.
所以也要检查这种可能性。
回答by Joan-Diego Rodriguez
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:
该对象很可能不存在。请向我们展示您如何创建它的代码。如果您在另一个类中使用它(例如,可能在 __construct 函数中创建它),请使用:
$ip2c = new Class;
Won't cut it. Instead do:
不会剪。而是这样做:
$this->ip2c = new Class;
and then
进而
$this->ip2c->mysql_con();

