3v4l.org

run code in 200+ php & hhvm versions
Bugs & Features
<?php function needArray(Iterable $arr) { $arr[] = 'hi'; return $arr; } class obj implements ArrayAccess { private $container = array(); public function __construct() { $this->container = array( "one" => 1, "two" => 2, "three" => 3, ); } public function offsetSet($offset, $value) { if (is_null($offset)) { $this->container[] = $value; } else { $this->container[$offset] = $value; } } public function offsetExists($offset) { return isset($this->container[$offset]); } public function offsetUnset($offset) { unset($this->container[$offset]); } public function offsetGet($offset) { return isset($this->container[$offset]) ? $this->container[$offset] : null; } } $obj = new obj; echo "testing with ArrayAccess\n"; var_dump(needArray($obj)); $arr = []; echo "testing with array\n"; var_dump(needArray($arr));
based on FOEP0
Output for 7.1.0 - 7.3.0beta1
testing with ArrayAccess Fatal error: Uncaught TypeError: Argument 1 passed to needArray() must be iterable, object given, called in /in/Fv2qF on line 44 and defined in /in/Fv2qF:3 Stack trace: #0 /in/Fv2qF(44): needArray(Object(obj)) #1 {main} thrown in /in/Fv2qF on line 3
Process exited with code 255.
Output for hhvm-3.22.0
testing with ArrayAccess Fatal error: Uncaught TypeError: Argument 1 passed to needArray() must be an instance of Iterable, obj given in /in/Fv2qF:-1 Stack trace: #0 /in/Fv2qF(-1): needArray() #1 {main}
Process exited with code 255.
Output for hhvm-3.18.5 - 3.21.3
testing with ArrayAccess Fatal error: Uncaught TypeError: Argument 1 passed to needArray() must be an instance of Iterable, obj given in /in/Fv2qF:7 Stack trace: #0 /in/Fv2qF(44): needArray() #1 {main}
Process exited with code 255.
Output for 5.6.0 - 5.6.30
testing with ArrayAccess Catchable fatal error: Argument 1 passed to needArray() must be an instance of Iterable, instance of obj given, called in /in/Fv2qF on line 44 and defined in /in/Fv2qF on line 3
Process exited with code 255.