-2
我也許是PHP使用過的最令人困惑的問題。請看下面的代碼:只有寫入順序中的最後一個變量
public $profile;
public $account;
function __construct(){
if(isset($_SESSION['uid'])){
$this->$profile = $_SESSION['user_profile'];
$this->$account = $_SESSION['user_account'];
echo "<script> alert('".$this->$profile->forename."'); </script>"; //Shows nothing
}else{
unset($_SESSION['user_profile']);
unset($_SESSION['user_account']);
}
}
出於某種原因,似乎無論是$this->$profile
將寫入或$this->$account
會寫,但只有當它是最後一個。在上面的情況下,如果我將配置文件行移到帳戶行後面,它將被寫入。但是,在這種情況下並非如此。
兩個$_SESSION
變量都是從SQL語句中檢索的對象,並且它們的分配是有效的,因爲直接訪問任一變量(例如$_SESSION['user_profile']->forename
)都可以正常工作。
任何想法?謝謝。
嘗試使用'$這個 - > profile'和'$這個 - > account',而不是'$此 - > $ profile', '$ this - > $ account' –
well spotted @RyanHipkiss – Dale
@RyanHipkiss這似乎工作。你知道爲什麼嗎?我認爲我以前沒有遇到過麻煩。感謝您的評論。 – user3642576