2014-02-05 48 views
0

推入數組中的對象屬性的正確方法是什麼?推入屬於對象屬性的數組的正確方法是什麼?

錯誤:

Fatal error: Cannot use [] for reading in ... on line .. 

代碼:

class StreamResponse 
{ 
    public $messages ; 

    function __construct($post) 
    { 
    $strippost = stripslashes_deep($_POST);  
    foreach ($strippost['messages'] as $message) 
    { 
     $m = json_decode($message, true); 
     $this->$messages[] = $m; //<-- This line is the line with the issue 
    } 
    } 
} 

回答

2

當您使用$this

$this->messages[] = $m;

不要使用 messages前的美元符號
相關問題