Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Sometimes it is worth writing a simple test, saving to a separate file, and then running script through the PHP interpreter from the command-line. When debugging complicated code, it is easy to bark up the wrong tree. If you are feeling ambitious, you can take it one step further and explore writing unit tests using PHPUnit.</p> <pre><code>&lt;?php $statuses = array( 'test1', 'test2', 'test3', 'test4', 'test5', 'test6', 'test7', 'test8', 'test9', 'test10', 'test11' ); class StatusMessage { private $status; function __construct($status) { $this-&gt;status = $status; } function getInteractions() { return $this-&gt;status . " interactions"; } function getMessage() { return $this-&gt;status . " messages"; } } function collectStatuses($statusesAPI){ $statusObjects = Array(); foreach($statusesAPI as $status) { //StatusMessage is a class I created array_push($statusObjects, new StatusMessage($status)); } return $statusObjects; } //$statutuses[data] was populated further up $statObjs = collectStatuses($statuses); //This loop works, but prints all StatusMessage objects in $statObjs foreach ($statObjs as $value) { //getInteractions() and getMessages() are both member functions of the StatusMessage class I created. echo '[' . $value-&gt;getInteractions() . '] ' . $value-&gt;getMessage() . "\n"; } //This loop doesn't work. Throws the error mentioned above for ($i = 0; $i &lt; 10; $i++) { echo '[' . $statObjs[$i]-&gt;getInteractions() . '] ' . $statObjs[$i]-&gt;getMessage() . "\n"; } ?&gt; </code></pre>
    singulars
    1. This table or related slice is empty.
    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. This table or related slice is empty.
    1. This table or related slice is empty.
    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