gpt4 book ai didi

php - 从 PHP 中的静态方法访问私有(private)

转载 作者:行者123 更新时间:2023-12-04 05:06:07 25 4
gpt4 key购买 nike

为什么这行得通?我的意思是,访问私有(private)变量。

类测试{
私有(private) $q = 0;
公共(public)函数 __construct() {
$this->q = 1;
}
公共(public)静态函数 EpicConstruct() {
$test = 新的自我();
$test->q = 2;
返回$测试;
}
}

$test = Test::EpicConstruct();

最佳答案

因为您在正确的上下文中访问成员,即:定义私有(private)成员的类。

关于php - 从 PHP 中的静态方法访问私有(private),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15510421/

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