推入作为对象属性的数组的正确方法是什么?
错误:
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
}
}
}
答案 0 :(得分:2)
使用messages
$this