Search code examples
phpsymfony-1.4propel

Null has class?


Symfony 1.4 and Propel are involved but I'm not sure they cause strange behaviour described below.

$this->_parent = TestPeer::retrieveByPK($this->getParentId());
var_dump(get_class($this->_parent), $this->_parent);

prints out 'Test' and 'null'.

How can it be this way?

PS

1/ $this->getParentId() returns integer and there is no corresponding record in DB, so $this->_parent should be null.

2/ php 5.5.6, xdebug, opcache


Solution

  • Quote from The PHP Manual for 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.

    Which together with:

    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.

    ...means that when passing null, you get the name of the class containing the call.