簡體   English   中英

推入作為對象屬性的數組的正確方法是什么?

[英]What is the correct way to push into an array that is a property of an object?

推入作為對象屬性的數組的正確方法是什么?

錯誤:

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
    }
  }
}

當你使用$this時,不要在messages之前使用美元符號

$this->messages[] = $m;

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM