3v4l.org

run code in 150+ php & hhvm versions
Bugs & Features
<?php class MyModel { } class Collection implements \ArrayAccess, \Iterator { private $storage = array(); public function offsetExists($offset) { return isset($this->storage[$offset]); } public function offsetGet($offset) { return $this->storage[$offset]; } public function offsetSet($offset, $value) { if (null === $offset) { $this->storage[] = $value; } else { $this->storage[$offset] = $value; } } public function offsetUnset($offset) { echo 'trying to unset ' . $offset . PHP_EOL; unset($this->storage[$offset]); } public function current() { return current($this->storage); } public function next() { return next($this->storage); } public function key() { return key($this->current()); } public function valid() { return key($this->storage) !== null; } public function rewind() { reset($this->storage); } public function count() { return count($this->storage); } } class MyCollectionModel { private $collection; public function __construct() { $this->collection = new Collection(); } public function addElement($element) { $this->collection[] = $element; } public function removeMyModels() { foreach ($this->collection as $index => $value) { if ($value instanceof MyModel) { unset ($this->collection[$index]); } } } } // Создем коллекцию $myCollection = new MyCollectionModel(); // Заполняем своими можельками for ($i = 0; $i < 10; $i++) { $myCollection->addElement(new MyModel()); } // Удаляем свои модельки $myCollection->removeMyModels(); // Сука, ебучая PHP!!! print_r($myCollection);
based on UuIpu
Output for 5.5.24 - 5.6.28, 7.0.0 - 7.1.0
trying to unset trying to unset trying to unset trying to unset trying to unset trying to unset trying to unset trying to unset trying to unset trying to unset MyCollectionModel Object ( [collection:MyCollectionModel:private] => Collection Object ( [storage:Collection:private] => Array ( [0] => MyModel Object ( ) [1] => MyModel Object ( ) [2] => MyModel Object ( ) [3] => MyModel Object ( ) [4] => MyModel Object ( ) [5] => MyModel Object ( ) [6] => MyModel Object ( ) [7] => MyModel Object ( ) [8] => MyModel Object ( ) [9] => MyModel Object ( ) ) ) )
Output for hhvm-3.10.0 - 3.12.0
Warning: Invalid operand type was used: expecting an array in /in/k8FnZ on line 48 trying to unset Warning: Invalid operand type was used: expecting an array in /in/k8FnZ on line 48 trying to unset Warning: Invalid operand type was used: expecting an array in /in/k8FnZ on line 48 trying to unset Warning: Invalid operand type was used: expecting an array in /in/k8FnZ on line 48 trying to unset Warning: Invalid operand type was used: expecting an array in /in/k8FnZ on line 48 trying to unset Warning: Invalid operand type was used: expecting an array in /in/k8FnZ on line 48 trying to unset Warning: Invalid operand type was used: expecting an array in /in/k8FnZ on line 48 trying to unset Warning: Invalid operand type was used: expecting an array in /in/k8FnZ on line 48 trying to unset Warning: Invalid operand type was used: expecting an array in /in/k8FnZ on line 48 trying to unset MyCollectionModel Object ( [collection:MyCollectionModel:private] => Collection Object ( [storage:Collection:private] => Array ( [1] => MyModel Object ( ) [2] => MyModel Object ( ) [3] => MyModel Object ( ) [4] => MyModel Object ( ) [5] => MyModel Object ( ) [6] => MyModel Object ( ) [7] => MyModel Object ( ) [8] => MyModel Object ( ) [9] => MyModel Object ( ) ) ) )
Output for 5.3.0 - 5.4.45
trying to unset 0 trying to unset 0 trying to unset 0 trying to unset 0 trying to unset 0 trying to unset 0 trying to unset 0 trying to unset 0 trying to unset 0 MyCollectionModel Object ( [collection:MyCollectionModel:private] => Collection Object ( [storage:Collection:private] => Array ( [1] => MyModel Object ( ) [2] => MyModel Object ( ) [3] => MyModel Object ( ) [4] => MyModel Object ( ) [5] => MyModel Object ( ) [6] => MyModel Object ( ) [7] => MyModel Object ( ) [8] => MyModel Object ( ) [9] => MyModel Object ( ) ) ) )
Output for 5.0.2 - 5.0.4, 5.1.0 - 5.2.17
Warning: Unexpected character in input: '\' (ASCII=92) state=1 in /in/k8FnZ on line 7 Warning: Unexpected character in input: '\' (ASCII=92) state=1 in /in/k8FnZ on line 7 trying to unset 0 trying to unset 0 trying to unset 0 trying to unset 0 trying to unset 0 trying to unset 0 trying to unset 0 trying to unset 0 trying to unset 0 MyCollectionModel Object ( [collection:private] => Collection Object ( [storage:private] => Array ( [1] => MyModel Object ( ) [2] => MyModel Object ( ) [3] => MyModel Object ( ) [4] => MyModel Object ( ) [5] => MyModel Object ( ) [6] => MyModel Object ( ) [7] => MyModel Object ( ) [8] => MyModel Object ( ) [9] => MyModel Object ( ) ) ) )
Output for 5.0.5
Warning: Unexpected character in input: '\' (ASCII=92) state=1 in /in/k8FnZ on line 7 Warning: Unexpected character in input: '\' (ASCII=92) state=1 in /in/k8FnZ on line 7 Fatal error: Only variables can be passed by reference in /in/k8FnZ on line 48
Process exited with code 255.
Output for 5.0.0 - 5.0.1
Warning: Unexpected character in input: '\' (ASCII=92) state=1 in /in/k8FnZ on line 7 Warning: Unexpected character in input: '\' (ASCII=92) state=1 in /in/k8FnZ on line 7 Notice: Use of undefined constant PHP_EOL - assumed 'PHP_EOL' in /in/k8FnZ on line 32 trying to unset 0PHP_EOL Notice: Use of undefined constant PHP_EOL - assumed 'PHP_EOL' in /in/k8FnZ on line 32 trying to unset 0PHP_EOL Notice: Use of undefined constant PHP_EOL - assumed 'PHP_EOL' in /in/k8FnZ on line 32 trying to unset 0PHP_EOL Notice: Use of undefined constant PHP_EOL - assumed 'PHP_EOL' in /in/k8FnZ on line 32 trying to unset 0PHP_EOL Notice: Use of undefined constant PHP_EOL - assumed 'PHP_EOL' in /in/k8FnZ on line 32 trying to unset 0PHP_EOL Notice: Use of undefined constant PHP_EOL - assumed 'PHP_EOL' in /in/k8FnZ on line 32 trying to unset 0PHP_EOL Notice: Use of undefined constant PHP_EOL - assumed 'PHP_EOL' in /in/k8FnZ on line 32 trying to unset 0PHP_EOL Notice: Use of undefined constant PHP_EOL - assumed 'PHP_EOL' in /in/k8FnZ on line 32 trying to unset 0PHP_EOL Notice: Use of undefined constant PHP_EOL - assumed 'PHP_EOL' in /in/k8FnZ on line 32 trying to unset 0PHP_EOLMyCollectionModel Object ( [collection:private] => Collection Object ( [storage:private] => Array ( [1] => MyModel Object ( ) [2] => MyModel Object ( ) [3] => MyModel Object ( ) [4] => MyModel Object ( ) [5] => MyModel Object ( ) [6] => MyModel Object ( ) [7] => MyModel Object ( ) [8] => MyModel Object ( ) [9] => MyModel Object ( ) ) ) )
Output for 4.4.2 - 4.4.9
Parse error: syntax error, unexpected T_STRING, expecting '{' in /in/k8FnZ on line 7
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/k8FnZ on line 7
Process exited with code 255.
Output for 4.3.2 - 4.3.4
Parse error: parse error, expecting `'{'' in /in/k8FnZ on line 7
Process exited with code 255.