我爱占星网 我爱占星网
首页
编程
java
php
前端
首页 编程 java php 前端

在PHP中从静态方法访问私有

Why this works? I mean, accessing the private variable.

class Test {
    private $q = 0;
    public function __construct() {
        $this->q = 1;
    }
    public static function EpicConstruct() {
        $test = new self();
        $test->q = 2;
        return $test;
    }
}

$test = Test::EpicConstruct();

Because you are accessing the member in the correct context, namely: the class that defines the private member.

近期文章

  • 如何检测上传的csv文件的编码
  • 为什么我的AJAX代码只能部分工作?
  • 返回匹配数组键的最大值
  • PHP从3维数组中获取数组值
  • Laravel 4可以保持套接字的日志错误吗?
  • SQL Server Symfony2的循环连接
  • Cakephp如何仅按日期和月份订购
  • PHP登录问题 - mysql_num_rows无效
  • 如何改变goutte的guzzle属性?
  • 如何使用PHP将数据库传递给excel?
  • 传递变量不会提交到数据库(PHP)
  • 在帖子过期后发送提醒电子邮件
  • 在foreach循环中填充PHP数组
  • Symfony2“所选选项不存在”
  • Laravel 4范围不适用于确切金额
  • Zend Framework - Zend_Session奇怪的行为
  • 使用php / javaBridge而不运行tomcat
  • PHP mysqli_fetch_assoc存储到一个数组中
  • 用于在sql php中存储折扣的数据类型[关闭]
  • Codeigniter项目中不断出现404错误

Copyright ©2022 我爱占星 All Rights Reserved.

浙ICP备2022030071号-1

部分图文来自网络,如有侵犯您的版权,请告诉我们删除

友情链接:代码精华