Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>The error message indicates that you are trying to all the <code>BattleInitiated()</code> method on something that wasn't an object.</p> <p>Judging from your code, the problem seems to be with this loop, in the <code>BeginBattle()</code> method :</p> <pre><code>foreach($this-&gt;_players as $player){ $player-&gt;BattleInitiated(); } </code></pre> <p>Which means $player, at least one in your array, is probably not an object ; maybe it's <code>null</code>, or an array ?</p> <p><br> To know more, you should use <code>var_dump</code> to display the content of <code>$this-&gt;_players</code> before the loop, just to make sure it contains what you expect it to :</p> <pre><code>public function BeginBattle(){ var_dump($this-&gt;_players); $this-&gt;_battleInProgress = TRUE; foreach($this-&gt;_players as $player){ $player-&gt;BattleInitiated(); } } </code></pre> <p>If <code>$this-&gt;_players</code> doesn't contain what you expect it to <em>(and it probably doesn't !)</em>, you'll then have to find out why...</p> <p><br> Considering <code>$this-&gt;_players</code> is modified by the <code>AddPlayer()</code> method, which adds what it receives to the end of the array, I would bet that <code>AddPlayer()</code> is called at least once without a correct <code>$player</code> as a parameter.</p> <p>To help with that, you could use <code>var_dump</code> on the <code>$player</code> being added :</p> <pre><code>public function AddPlayer($player){ var_dump($player); if(!$this-&gt;_battleInProgress) $this-&gt;_players[] = $player; else return; //Spit some error } </code></pre> <p>If that <code>var_dump</code> indicates at least once that <code>$player</code> is not an object <em>(for instance, it's <code>null</code>, or an array, or a string, ...)</em>, that's the cause of your Fatal Error.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload