2012-04-07 64 views
1

PHP CodePHP調用私有變量

<?php if (! defined('BASEPATH')) exit('No direct script access allowed'); 

class admin extends CI_Controller { 

    function __construct(){ 
     parent::__construct(); 
     $this->load->helper('ajax'); 
    } 

    private $password = 'password'; 

    private $login_details = array(
     'username' => 'username', 
     'password' => sha1('salt'.$this->password) 
    ); 

上述code返回以下PHP錯誤:

Parse error: syntax error, unexpected '(', expecting ')' 

我使用笨,但我不認爲這有什麼由於其基於PHP的問題...

+0

@safarov我知道,我不知道該如何解決它... – fxuser 2012-04-07 18:14:38

回答

2

類成員必須用靜態值進行初始化。您不能在初始化中使用函數結果,所以

'password' => sha1('salt'.$this->password) 

是禁止的。相反,您必須在構造函數中執行此操作。

+0

太棒了!謝謝... – fxuser 2012-04-07 18:17:33