gpt4 book ai didi

php - Null 有课吗?

转载 作者:可可西里 更新时间:2023-11-01 01:02:33 24 4
gpt4 key购买 nike

涉及 Symfony 1.4 和 Propel,但我不确定它们会导致下面描述的奇怪行为。

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

打印出 'Test' 和 'null'。

怎么会这样?

附言

1/$this->getParentId()返回整数,DB中没有对应的记录,所以$this->_parent应该为null。

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 时,您将获得包含调用的类的名称。

关于php - Null 有课吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20000765/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com