首先,让我说,以下情况并非一直发生,而是可能每天发生一次或两次(有时甚至不是一天一次)。此外,它只发生在生产中。所以我很难进行正确的调试,我所能做的就是捕获回溯并将其写在日志中。
我有一个 ORM 模型,它扩展了\Orm\Model
. 我Model_X::find()
用来获取所需的对象。但是,在该模型的构造函数中,奇怪的事情开始发生:
构造函数的第一行是
if( ! empty($this->_data))
这会触发 magic __isset('_data')
,然后调用 magic __get('_custom_data')
,从这一行:
elseif (array_key_exists($property, $this->_custom_data))
一直这样,直到最终抛出异常:
Undefined property: Model_X::$_view
从这一行:
elseif ($this->_view and in_array($property, static::$_views_cached[get_class($this)][$this->_view]['columns']))
奇怪的是,所有这些属性 _data、_view、_custom_data 都在\Orm\Model
类中定义。而我的理解是,如果定义了属性,就不需要调用__get,因为“与当前范围内未声明或不可见的属性或方法交互时会调用重载方法”
我的问题是:为什么 empty($this->_data) 调用 __isset (并触发所有后续调用),而事实上,该属性是为此类定义的?
这是回溯的相关部分:
"file": "/fuel/packages/orm/classes/model.php",
"line": 1028,
"function": "{closure}",
"args": [8, "Undefined property: Model_Supplier::$_view", "/fuel/packages/orm/classes/model.php", 1028, {
"property": "_view",
"rel": false,
"this": {},
"value": false
"file": "/fuel/packages/orm/classes/model.php",
"line": 865,
"function": "get",
"class": "Orm\\Model",
"object": {},
"type": "->",
"args": ["_view"]
"file": "/fuel/packages/orm/classes/model.php",
"line": 1028,
"function": "__get",
"class": "Orm\\Model",
"object": {},
"type": "->",
"args": ["_view"]
"file": "/fuel/packages/orm/classes/model.php",
"line": 865,
"function": "get",
"class": "Orm\\Model",
"object": {},
"type": "->",
"args": ["_custom_data"]
"file": "/fuel/packages/orm/classes/model.php",
"line": 899,
"function": "__get",
"class": "Orm\\Model",
"object": {},
"type": "->",
"args": ["_custom_data"]
"file": "/fuel/packages/orm/classes/model.php",
"line": 730,
"function": "__isset",
"class": "Orm\\Model",
"object": {},
"type": "->",
"args": ["_data"]
"file": "/fuel/packages/orm/classes/model.php",
"line": 124,
"function": "__construct",
"class": "Orm\\Model",
"object": {},
"type": "->",
编辑:我实际上已经解决了这个问题(我认为)。由于 php-fpm 重启后错误消失了,我的想法是 - 缓存损坏,重启后损坏的缓存被清理。唯一的缓存是 APC,所以我去禁用了它。