有人可以向我解释为什么访问空对象的属性(未分配var)时PHP不报告警告或错误吗?

例如:

$oMyObject->test = 'hello world'; // $oMyObject is not assigned but no warning or error

当我这样做时,它会产生一个错误:
$oMyObject->test(); // Error: Calling function on non-object

版本信息:
Windows XP
XAMPP Windows Version 1.7.0
Apache/2.2.11 (Win32)
PHP 5.2.8
Zend Engine v2.2.0, Copyright (c) 1998-2008 Zend Technologies
with Xdebug v2.0.4, Copyright (c) 2002-2008, by Derick Rethans

为什么?试图设置error_reporting(E_ALL),但仍然没有错误或警告。

最佳答案

$ oMyObject-> text ='hello world';是完全有效的声明,前提是文本被声明为公共(public)且非私有(private)或 protected 。至于$ oMyObject-> text(),您需要提供更多信息。您会遇到哪种错误?函数text()是公共(public)的还是私有(private)的或 protected ?您可以发布该功能做什么吗?

07-26 03:23