3v4l.org

run code in 300+ PHP versions simultaneously
<?php class MyArray { private $arrayRef; function __construct(&$array){ $this->arrayRef =& $array; } function addElement($newElement){ $this->arrayRef[] = $newElement; } function print(){ print_r($this->arrayRef); } } $array = ['first', 'second']; $arrayObject = new MyArray($array); $arrayObject->addElement('treci'); print_r($array); // prints array containing 2 elements echo '<br/>'; $arrayObject->print(); // prints array containing 3 elements
Output for 7.0.0 - 7.0.33, 7.1.0 - 7.1.33, 7.2.0 - 7.2.34, 7.3.0 - 7.3.33, 7.4.0 - 7.4.33, 8.0.0 - 8.0.30, 8.1.0 - 8.1.28, 8.2.0 - 8.2.18, 8.3.0 - 8.3.7
Array ( [0] => first [1] => second [2] => treci ) <br/>Array ( [0] => first [1] => second [2] => treci )
Output for 5.6.0 - 5.6.40
Parse error: syntax error, unexpected 'print' (T_PRINT), expecting identifier (T_STRING) in /in/XH54F on line 15
Process exited with code 255.

preferences:
218.63 ms | 401 KiB | 301 Q