gpt4 book ai didi

php - 在 php 中重载

转载 作者:可可西里 更新时间:2023-11-01 13:47:54 26 4
gpt4 key购买 nike

谁能说出下面给定行的含义是什么?

以下几行是从PHP manual复制而来的:

Note:

It is not possible to use overloaded properties in other language constructs than isset(). This means if empty() is called on an overloaded property, the overloaded method is not called.

To workaround that limitation, the overloaded property must be copied into a local variable in the scope and then be handed to empty().

但是我们不能在重载属性上调用 empty() 是不正确的,当我调用 empty() 时,它触发了 __isset()

最佳答案

这是一个文档错误:

<?php
class PropNameReturn {
function __isset($propname){
return true;

}
function __get($propname){
echo 'Yes, it IS called!'.PHP_EOL;
return $propname;
}
}
$o = new PropNameReturn();
var_dump(empty($o->this_prop_name));
//Yes, it IS called!
//bool(false)
$b = new stdClass();
var_dump(empty($b->this_prop_name));
//bool(true)

关于php - 在 php 中重载,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11063679/

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