gpt4 book ai didi

php - $this 的范围在 PHP 中是 funked 是错误还是功能?

转载 作者:可可西里 更新时间:2023-11-01 12:37:15 27 4
gpt4 key购买 nike

我有这个代码:

    class a(){
function b(){
if(isset($this){
echo 'instance! ';
echo get_class($this);
}else{
echo 'static';
}
}
}


class C{
public function test(){
a::b();
}
}

$CC=new C;
$CC->test();

这会回显

instance C

最佳答案

The pseudo-variable $this is available when a method is called from within an object context. $this is a reference to the calling object (usually the object to which the method belongs, but possibly another object, if the method is called statically from the context of a secondary object).

source

毫无疑问,这是一项功能,是设计使然,而不是错误。

关于php - $this 的范围在 PHP 中是 funked 是错误还是功能?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7539486/

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