对不起,这是另一个尝试获取非对象问题的属性...
这是一些代码,我似乎无法弄清楚这是如何工作的(或者不工作):
$b = Model_Artist::query()->where('id', 18)->get_one(); // Fuelphp ORM query, returns \Orm\Model object
var_dump($b); // output: object(Model_Artist)[46] ... etc.
// definitely an object
var_dump($b->id); // [Error: Trying to get property of non-object] output: '18'
// umm ok, so maybe no object?
var_dump(is_object($b)); // output: bool(true)
// no, no, it is an object!
var_dump($b->id); // [Error: Trying to get property of non-object] output: '18'
// make up your mind, it's no object after all?
if ( is_object($b) ) {
var_dump($b->id); // output: '18' [No error!!]
}
// WAT?? It is only an object inside the if statement?
所以问题是:为什么 PHP 说我property of a non-object
在前两种情况下尝试获取 a ,而is_object
is true
。为什么会在if
声明中突然改变?
要么PHP
很有趣,要么我做错了什么?