3v4l.org

run code in 150+ php & hhvm versions
Bugs & Features
<?php class ArrayExtended implements ArrayAccess{ protected $ary = array(); public function __construct(array $a = null) { if($a) $this->ary = $a; } // Useful methods public function reverse() { $this->ary = array_reverse($this->ary); return $this; } // Mandatory methods for ArrayAccess implementation public function offsetExists($off){return array_key_exists($off,$this->ary);} public function offsetGet($off){return $this->ary[$off];} public function offsetSet($off,$val){if(is_null($off)) $this->ary[]=$val; else $this->ary[$off]=$val;} public function offsetUnset($off){unset($this->ary[$off]);} } $o = new ArrayExtended(array('a','b')); $o[] = 'c'; print_r($o->reverse());
Output for 5.1.0 - 7.1.0
ArrayExtended Object ( [ary:protected] => Array ( [0] => c [1] => b [2] => a ) )
Output for 5.0.0 - 5.0.5
Parse error: parse error, unexpected T_ARRAY, expecting '&' or T_VARIABLE in /in/jTRM6 on line 6
Process exited with code 255.
Output for 4.4.2 - 4.4.9
Parse error: syntax error, unexpected T_STRING, expecting '{' in /in/jTRM6 on line 3
Process exited with code 255.
Output for 4.3.0 - 4.3.1, 4.3.5 - 4.4.1
Parse error: parse error, unexpected T_STRING, expecting '{' in /in/jTRM6 on line 3
Process exited with code 255.
Output for 4.3.2 - 4.3.4
Parse error: parse error, expecting `'{'' in /in/jTRM6 on line 3
Process exited with code 255.