PHP-空有类?
作者:互联网
涉及到Symfony 1.4和Propel,但我不确定它们是否会导致以下所述的奇怪行为.
$this->_parent = TestPeer::retrieveByPK($this->getParentId());
var_dump(get_class($this->_parent), $this->_parent);
打印出“ Test”和“ null”.
怎么会这样呢
聚苯乙烯
1 / $this-> getParentId()返回整数,并且数据库中没有相应的记录,因此$this-> _parent应该为空.
2 / PHP 5.5.6,xdebug,opcache
解决方法:
从The PHP Manual引用get_class:
5.3.0 NULL became the default value for object, so passing NULL to object now has the same result as not passing any value.
连同:
Returns the name of the class of which object is an instance. Returns
FALSE if object is not an object.If object is omitted when inside a class, the name of that class is
returned.
…表示在传递null时,您将获得包含该调用的类的名称.
标签:symfony-1-4,propel,php 来源: https://codeday.me/bug/20191030/1966018.html