3v4l.org

run code in 300+ PHP versions simultaneously
<?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]); var_dump($this->storage); } public function current() { return current($this->storage); } public function next() { return next($this->storage); } public function key() { return key($this->storage); } 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) { var_dump($index); 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);
Output for 8.1.0 - 8.1.28, 8.2.0 - 8.2.18, 8.3.0 - 8.3.6
Deprecated: Return type of Collection::offsetExists($offset) should either be compatible with ArrayAccess::offsetExists(mixed $offset): bool, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /in/70mO8 on line 11 Deprecated: Return type of Collection::offsetGet($offset) should either be compatible with ArrayAccess::offsetGet(mixed $offset): mixed, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /in/70mO8 on line 16 Deprecated: Return type of Collection::offsetSet($offset, $value) should either be compatible with ArrayAccess::offsetSet(mixed $offset, mixed $value): void, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /in/70mO8 on line 21 Deprecated: Return type of Collection::offsetUnset($offset) should either be compatible with ArrayAccess::offsetUnset(mixed $offset): void, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /in/70mO8 on line 30 Deprecated: Return type of Collection::current() should either be compatible with Iterator::current(): mixed, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /in/70mO8 on line 37 Deprecated: Return type of Collection::next() should either be compatible with Iterator::next(): void, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /in/70mO8 on line 42 Deprecated: Return type of Collection::key() should either be compatible with Iterator::key(): mixed, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /in/70mO8 on line 47 Deprecated: Return type of Collection::valid() should either be compatible with Iterator::valid(): bool, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /in/70mO8 on line 52 Deprecated: Return type of Collection::rewind() should either be compatible with Iterator::rewind(): void, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /in/70mO8 on line 57 int(0) trying to unset 0 array(9) { [1]=> object(MyModel)#4 (0) { } [2]=> object(MyModel)#5 (0) { } [3]=> object(MyModel)#6 (0) { } [4]=> object(MyModel)#7 (0) { } [5]=> object(MyModel)#8 (0) { } [6]=> object(MyModel)#9 (0) { } [7]=> object(MyModel)#10 (0) { } [8]=> object(MyModel)#11 (0) { } [9]=> object(MyModel)#12 (0) { } } int(2) trying to unset 2 array(8) { [1]=> object(MyModel)#4 (0) { } [3]=> object(MyModel)#6 (0) { } [4]=> object(MyModel)#7 (0) { } [5]=> object(MyModel)#8 (0) { } [6]=> object(MyModel)#9 (0) { } [7]=> object(MyModel)#10 (0) { } [8]=> object(MyModel)#11 (0) { } [9]=> object(MyModel)#12 (0) { } } int(4) trying to unset 4 array(7) { [1]=> object(MyModel)#4 (0) { } [3]=> object(MyModel)#6 (0) { } [5]=> object(MyModel)#8 (0) { } [6]=> object(MyModel)#9 (0) { } [7]=> object(MyModel)#10 (0) { } [8]=> object(MyModel)#11 (0) { } [9]=> object(MyModel)#12 (0) { } } int(6) trying to unset 6 array(6) { [1]=> object(MyModel)#4 (0) { } [3]=> object(MyModel)#6 (0) { } [5]=> object(MyModel)#8 (0) { } [7]=> object(MyModel)#10 (0) { } [8]=> object(MyModel)#11 (0) { } [9]=> object(MyModel)#12 (0) { } } int(8) trying to unset 8 array(5) { [1]=> object(MyModel)#4 (0) { } [3]=> object(MyModel)#6 (0) { } [5]=> object(MyModel)#8 (0) { } [7]=> object(MyModel)#10 (0) { } [9]=> object(MyModel)#12 (0) { } } MyCollectionModel Object ( [collection:MyCollectionModel:private] => Collection Object ( [storage:Collection:private] => Array ( [1] => MyModel Object ( ) [3] => MyModel Object ( ) [5] => MyModel Object ( ) [7] => MyModel Object ( ) [9] => MyModel Object ( ) ) ) )
Output for 5.3.0 - 5.3.29, 5.4.0 - 5.4.45, 5.5.0 - 5.5.38, 5.6.0 - 5.6.40, 7.0.0 - 7.0.33, 7.1.0 - 7.1.33, 7.2.0 - 7.2.33, 7.3.0 - 7.3.33, 7.4.0 - 7.4.33, 8.0.0 - 8.0.30
int(0) trying to unset 0 array(9) { [1]=> object(MyModel)#4 (0) { } [2]=> object(MyModel)#5 (0) { } [3]=> object(MyModel)#6 (0) { } [4]=> object(MyModel)#7 (0) { } [5]=> object(MyModel)#8 (0) { } [6]=> object(MyModel)#9 (0) { } [7]=> object(MyModel)#10 (0) { } [8]=> object(MyModel)#11 (0) { } [9]=> object(MyModel)#12 (0) { } } int(2) trying to unset 2 array(8) { [1]=> object(MyModel)#4 (0) { } [3]=> object(MyModel)#6 (0) { } [4]=> object(MyModel)#7 (0) { } [5]=> object(MyModel)#8 (0) { } [6]=> object(MyModel)#9 (0) { } [7]=> object(MyModel)#10 (0) { } [8]=> object(MyModel)#11 (0) { } [9]=> object(MyModel)#12 (0) { } } int(4) trying to unset 4 array(7) { [1]=> object(MyModel)#4 (0) { } [3]=> object(MyModel)#6 (0) { } [5]=> object(MyModel)#8 (0) { } [6]=> object(MyModel)#9 (0) { } [7]=> object(MyModel)#10 (0) { } [8]=> object(MyModel)#11 (0) { } [9]=> object(MyModel)#12 (0) { } } int(6) trying to unset 6 array(6) { [1]=> object(MyModel)#4 (0) { } [3]=> object(MyModel)#6 (0) { } [5]=> object(MyModel)#8 (0) { } [7]=> object(MyModel)#10 (0) { } [8]=> object(MyModel)#11 (0) { } [9]=> object(MyModel)#12 (0) { } } int(8) trying to unset 8 array(5) { [1]=> object(MyModel)#4 (0) { } [3]=> object(MyModel)#6 (0) { } [5]=> object(MyModel)#8 (0) { } [7]=> object(MyModel)#10 (0) { } [9]=> object(MyModel)#12 (0) { } } MyCollectionModel Object ( [collection:MyCollectionModel:private] => Collection Object ( [storage:Collection:private] => Array ( [1] => MyModel Object ( ) [3] => MyModel Object ( ) [5] => MyModel Object ( ) [7] => MyModel Object ( ) [9] => MyModel Object ( ) ) ) )
Output for 5.0.2 - 5.0.5, 5.1.0 - 5.1.6, 5.2.0 - 5.2.17
Warning: Unexpected character in input: '\' (ASCII=92) state=1 in /in/70mO8 on line 7 Warning: Unexpected character in input: '\' (ASCII=92) state=1 in /in/70mO8 on line 7 int(0) trying to unset 0 array(9) { [1]=> object(MyModel)#4 (0) { } [2]=> object(MyModel)#5 (0) { } [3]=> object(MyModel)#6 (0) { } [4]=> object(MyModel)#7 (0) { } [5]=> object(MyModel)#8 (0) { } [6]=> object(MyModel)#9 (0) { } [7]=> object(MyModel)#10 (0) { } [8]=> object(MyModel)#11 (0) { } [9]=> object(MyModel)#12 (0) { } } int(2) trying to unset 2 array(8) { [1]=> object(MyModel)#4 (0) { } [3]=> object(MyModel)#6 (0) { } [4]=> object(MyModel)#7 (0) { } [5]=> object(MyModel)#8 (0) { } [6]=> object(MyModel)#9 (0) { } [7]=> object(MyModel)#10 (0) { } [8]=> object(MyModel)#11 (0) { } [9]=> object(MyModel)#12 (0) { } } int(4) trying to unset 4 array(7) { [1]=> object(MyModel)#4 (0) { } [3]=> object(MyModel)#6 (0) { } [5]=> object(MyModel)#8 (0) { } [6]=> object(MyModel)#9 (0) { } [7]=> object(MyModel)#10 (0) { } [8]=> object(MyModel)#11 (0) { } [9]=> object(MyModel)#12 (0) { } } int(6) trying to unset 6 array(6) { [1]=> object(MyModel)#4 (0) { } [3]=> object(MyModel)#6 (0) { } [5]=> object(MyModel)#8 (0) { } [7]=> object(MyModel)#10 (0) { } [8]=> object(MyModel)#11 (0) { } [9]=> object(MyModel)#12 (0) { } } int(8) trying to unset 8 array(5) { [1]=> object(MyModel)#4 (0) { } [3]=> object(MyModel)#6 (0) { } [5]=> object(MyModel)#8 (0) { } [7]=> object(MyModel)#10 (0) { } [9]=> object(MyModel)#12 (0) { } } MyCollectionModel Object ( [collection:private] => Collection Object ( [storage:private] => Array ( [1] => MyModel Object ( ) [3] => MyModel Object ( ) [5] => MyModel Object ( ) [7] => MyModel Object ( ) [9] => MyModel Object ( ) ) ) )
Output for 5.0.0 - 5.0.1
Warning: Unexpected character in input: '\' (ASCII=92) state=1 in /in/70mO8 on line 7 Warning: Unexpected character in input: '\' (ASCII=92) state=1 in /in/70mO8 on line 7 int(0) Notice: Use of undefined constant PHP_EOL - assumed 'PHP_EOL' in /in/70mO8 on line 32 trying to unset 0PHP_EOLarray(9) { [1]=> object(MyModel)#4 (0) { } [2]=> object(MyModel)#5 (0) { } [3]=> object(MyModel)#6 (0) { } [4]=> object(MyModel)#7 (0) { } [5]=> object(MyModel)#8 (0) { } [6]=> object(MyModel)#9 (0) { } [7]=> object(MyModel)#10 (0) { } [8]=> object(MyModel)#11 (0) { } [9]=> object(MyModel)#12 (0) { } } int(2) Notice: Use of undefined constant PHP_EOL - assumed 'PHP_EOL' in /in/70mO8 on line 32 trying to unset 2PHP_EOLarray(8) { [1]=> object(MyModel)#4 (0) { } [3]=> object(MyModel)#6 (0) { } [4]=> object(MyModel)#7 (0) { } [5]=> object(MyModel)#8 (0) { } [6]=> object(MyModel)#9 (0) { } [7]=> object(MyModel)#10 (0) { } [8]=> object(MyModel)#11 (0) { } [9]=> object(MyModel)#12 (0) { } } int(4) Notice: Use of undefined constant PHP_EOL - assumed 'PHP_EOL' in /in/70mO8 on line 32 trying to unset 4PHP_EOLarray(7) { [1]=> object(MyModel)#4 (0) { } [3]=> object(MyModel)#6 (0) { } [5]=> object(MyModel)#8 (0) { } [6]=> object(MyModel)#9 (0) { } [7]=> object(MyModel)#10 (0) { } [8]=> object(MyModel)#11 (0) { } [9]=> object(MyModel)#12 (0) { } } int(6) Notice: Use of undefined constant PHP_EOL - assumed 'PHP_EOL' in /in/70mO8 on line 32 trying to unset 6PHP_EOLarray(6) { [1]=> object(MyModel)#4 (0) { } [3]=> object(MyModel)#6 (0) { } [5]=> object(MyModel)#8 (0) { } [7]=> object(MyModel)#10 (0) { } [8]=> object(MyModel)#11 (0) { } [9]=> object(MyModel)#12 (0) { } } int(8) Notice: Use of undefined constant PHP_EOL - assumed 'PHP_EOL' in /in/70mO8 on line 32 trying to unset 8PHP_EOLarray(5) { [1]=> object(MyModel)#4 (0) { } [3]=> object(MyModel)#6 (0) { } [5]=> object(MyModel)#8 (0) { } [7]=> object(MyModel)#10 (0) { } [9]=> object(MyModel)#12 (0) { } } MyCollectionModel Object ( [collection:private] => Collection Object ( [storage:private] => Array ( [1] => MyModel Object ( ) [3] => MyModel Object ( ) [5] => MyModel Object ( ) [7] => MyModel Object ( ) [9] => MyModel Object ( ) ) ) )
Output for 4.4.2 - 4.4.9
Parse error: syntax error, unexpected T_STRING, expecting '{' in /in/70mO8 on line 7
Process exited with code 255.
Output for 4.3.0 - 4.3.1, 4.3.5 - 4.3.11, 4.4.0 - 4.4.1
Parse error: parse error, unexpected T_STRING, expecting '{' in /in/70mO8 on line 7
Process exited with code 255.
Output for 4.3.2 - 4.3.4
Parse error: parse error, expecting `'{'' in /in/70mO8 on line 7
Process exited with code 255.

preferences:
266.16 ms | 401 KiB | 459 Q