3v4l.org

run code in 300+ PHP versions simultaneously
<?php class a implements \Iterator, \Countable { private $a; private $b; private $c; private $keys = [ 'a', 'b', 'c' ]; private $pointer; public function __construc($a = null, $b = null, $c = null) { $this->a = $a; $this->b = $b; $this->c = $c; } public function count() { $pointer = 0; foreach ($this as $element) { if ($element) { $pointer++; } } return $pointer; } public function current() { $key = $this->key(); return $this->{$key}; } public function key() { $this->keys[$this->pointer]; } public function next() { $this->pointer++; } public function valid() { return $this->pointer < count($this->keys); } public function rewind() { $this->pointer = 0; } } $me = new a('a'); var_dump($me->count()); foreach ($me as $key => $el) { var_dump($key, $el); }
Output for 8.1.0 - 8.1.28, 8.2.0 - 8.2.18, 8.3.0 - 8.3.4, 8.3.6
Deprecated: Return type of a::current() should either be compatible with Iterator::current(): mixed, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /in/jEEBM on line 37 Deprecated: Return type of a::next() should either be compatible with Iterator::next(): void, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /in/jEEBM on line 49 Deprecated: Return type of a::key() should either be compatible with Iterator::key(): mixed, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /in/jEEBM on line 44 Deprecated: Return type of a::valid() should either be compatible with Iterator::valid(): bool, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /in/jEEBM on line 54 Deprecated: Return type of a::rewind() should either be compatible with Iterator::rewind(): void, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /in/jEEBM on line 59 Deprecated: Return type of a::count() should either be compatible with Countable::count(): int, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /in/jEEBM on line 24 Warning: Undefined property: a::$ in /in/jEEBM on line 41 Warning: Undefined property: a::$ in /in/jEEBM on line 41 Warning: Undefined property: a::$ in /in/jEEBM on line 41 int(0) Warning: Undefined property: a::$ in /in/jEEBM on line 41 NULL NULL Warning: Undefined property: a::$ in /in/jEEBM on line 41 NULL NULL Warning: Undefined property: a::$ in /in/jEEBM on line 41 NULL NULL
Output for 8.3.5
Warning: PHP Startup: Unable to load dynamic library 'sodium.so' (tried: /usr/lib/php/8.3.5/modules/sodium.so (libsodium.so.23: cannot open shared object file: No such file or directory), /usr/lib/php/8.3.5/modules/sodium.so.so (/usr/lib/php/8.3.5/modules/sodium.so.so: cannot open shared object file: No such file or directory)) in Unknown on line 0 Deprecated: Return type of a::current() should either be compatible with Iterator::current(): mixed, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /in/jEEBM on line 37 Deprecated: Return type of a::next() should either be compatible with Iterator::next(): void, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /in/jEEBM on line 49 Deprecated: Return type of a::key() should either be compatible with Iterator::key(): mixed, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /in/jEEBM on line 44 Deprecated: Return type of a::valid() should either be compatible with Iterator::valid(): bool, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /in/jEEBM on line 54 Deprecated: Return type of a::rewind() should either be compatible with Iterator::rewind(): void, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /in/jEEBM on line 59 Deprecated: Return type of a::count() should either be compatible with Countable::count(): int, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /in/jEEBM on line 24 Warning: Undefined property: a::$ in /in/jEEBM on line 41 Warning: Undefined property: a::$ in /in/jEEBM on line 41 Warning: Undefined property: a::$ in /in/jEEBM on line 41 int(0) Warning: Undefined property: a::$ in /in/jEEBM on line 41 NULL NULL Warning: Undefined property: a::$ in /in/jEEBM on line 41 NULL NULL Warning: Undefined property: a::$ in /in/jEEBM on line 41 NULL NULL
Output for 8.0.0 - 8.0.30
Warning: Undefined property: a::$ in /in/jEEBM on line 41 Warning: Undefined property: a::$ in /in/jEEBM on line 41 Warning: Undefined property: a::$ in /in/jEEBM on line 41 int(0) Warning: Undefined property: a::$ in /in/jEEBM on line 41 NULL NULL Warning: Undefined property: a::$ in /in/jEEBM on line 41 NULL NULL Warning: Undefined property: a::$ in /in/jEEBM on line 41 NULL NULL
Output for 7.1.0 - 7.1.33, 7.2.0 - 7.2.33, 7.3.0 - 7.3.31, 7.4.0 - 7.4.33
Notice: Undefined property: a::$ in /in/jEEBM on line 41 Notice: Undefined property: a::$ in /in/jEEBM on line 41 Notice: Undefined property: a::$ in /in/jEEBM on line 41 int(0) Notice: Undefined property: a::$ in /in/jEEBM on line 41 NULL NULL Notice: Undefined property: a::$ in /in/jEEBM on line 41 NULL NULL Notice: Undefined property: a::$ in /in/jEEBM on line 41 NULL NULL
Output for 7.3.32 - 7.3.33
int(0) NULL NULL NULL NULL NULL NULL
Output for 7.0.0 - 7.0.20
Fatal error: Uncaught Error: Cannot access empty property in /in/jEEBM:41 Stack trace: #0 /in/jEEBM(28): a->current() #1 /in/jEEBM(67): a->count() #2 {main} thrown in /in/jEEBM on line 41
Process exited with code 255.
Output for 5.4.2 - 5.4.45, 5.5.24 - 5.5.35, 5.6.7 - 5.6.28
Fatal error: Cannot access empty property in /in/jEEBM on line 41
Process exited with code 255.

preferences:
208.81 ms | 402 KiB | 256 Q