【发布时间】:2014-02-19 12:21:35
【问题描述】:
class Auth extends Controller {
function __constructor(){
private $pass;
}
function Auth()
{
parent::Controller();
$this->load->library('session');
$this->load->helper('cookie');
$this->load->library('email');
}
function index(){
..........
}
function loging(){
$this->pass = "Hello World";
}
function test(){
var_dump($this->pass); // this is on the line 114
}
}
当我访问测试功能时,我得到了这个错误:
解析错误:语法错误,意外的 T_PRIVATE 在 /var/www/clients/client1/web15/web/application/controllers/auth.php 上 第 6 行
而不是字符串“Hello World”。我想知道为什么 ?谁能帮我这个 ?提前谢谢
【问题讨论】:
-
在不在其中的方法旁边声明类属性 (
private $pass;)。__constructor()也应该是__construct()。 -
想法是:如何更新函数中的私有变量并访问另一个函数中的更新值,当然是在同一个类中
-
那么@Rob 的回答对我来说很好。
标签: php oop global-variables private