3v4l.org

run code in 300+ PHP versions simultaneously
<?php class WrappingIterator implements \Iterator { private $index; private $iterator; public function __construct(int $index, Traversable $traversable) { printf('Creating %s %d' . PHP_EOL, static::class, $index); $this->index = $index; $this->iterator = $this->wrapTraversable($traversable); } public function __destruct() { printf('Destroying %s %d' . PHP_EOL, static::class, $this->index); } protected function destroyWrappedIterator() { $this->iterator = null; } public function current() { return $this->iterator->current(); } public function next() { $this->iterator->next(); } public function key() { return $this->iterator->key(); } public function valid() { return $this->iterator->valid(); } public function rewind() { $this->iterator->rewind(); } private function wrapTraversable(Traversable $traversable) { foreach ($traversable as $key => $value) { yield $key => $value; } } } class DestroyingIterator extends WrappingIterator { public function __destruct() { parent::__destruct(); $this->destroyWrappedIterator(); } } class WrappedIterator extends ArrayIterator { public function __construct(int $index) { parent::__construct([1, 2, 3, 4]); $this->index = $index; } public function __destruct() { printf('Destroying WrappedIterator %d' . PHP_EOL, $this->index); } } function testIterator(string $class, int $limit = 20) { printf('Starting run with class "%s" and limit "%d"' . PHP_EOL, $class, $limit); gc_enable(); gc_collect_cycles(); for ($i = 1; $i <= $limit; $i++) { $iterator = new $class($i, new WrappedIterator($i)); $iterator->current(); if ($i % 5 === 0) { gc_collect_cycles(); } } gc_collect_cycles(); echo 'Done', PHP_EOL; } testIterator(WrappingIterator::class); testIterator(DestroyingIterator::class);

Abusive script

This script was stopped while abusing our resources

Output for git.master, git.master_jit, rfc.property-hooks
Deprecated: Return type of WrappingIterator::current() should either be compatible with Iterator::current(): mixed, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /in/UIfIb on line 25 Deprecated: Return type of WrappingIterator::next() should either be compatible with Iterator::next(): void, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /in/UIfIb on line 30 Deprecated: Return type of WrappingIterator::key() should either be compatible with Iterator::key(): mixed, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /in/UIfIb on line 35 Deprecated: Return type of WrappingIterator::valid() should either be compatible with Iterator::valid(): bool, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /in/UIfIb on line 40 Deprecated: Return type of WrappingIterator::rewind() should either be compatible with Iterator::rewind(): void, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /in/UIfIb on line 45 Starting run with class "WrappingIterator" and limit "20" Deprecated: Creation of dynamic property WrappedIterator::$index is deprecated in /in/UIfIb on line 73 Creating WrappingIterator 1 Deprecated: Creation of dynamic property WrappedIterator::$index is deprecated in /in/UIfIb on line 73 Creating WrappingIterator 2 Deprecated: Creation of dynamic property WrappedIterator::$index is deprecated in /in/UIfIb on line 73 Creating WrappingIterator 3 Deprecated: Creation of dynamic property WrappedIterator::$index is deprecated in /in/UIfIb on line 73 Creating WrappingIterator 4 Deprecated: Creation of dynamic property WrappedIterator::$index is deprecated in /in/UIfIb on line 73 Creating WrappingIterator 5 Destroying WrappedIterator 1 Destroying WrappingIterator 1 Destroying WrappedIterator 2 Destroying WrappingIterator 2 Destroying WrappedIterator 3 Destroying WrappingIterator 3 Destroying WrappedIterator 4 Destroying WrappingIterator 4 Deprecated: Creation of dynamic property WrappedIterator::$index is deprecated in /in/UIfIb on line 73 Creating WrappingIterator 6 Deprecated: Creation of dynamic property WrappedIterator::$index is deprecated in /in/UIfIb on line 73 Creating WrappingIterator 7 Deprecated: Creation of dynamic property WrappedIterator::$index is deprecated in /in/UIfIb on line 73 Creating WrappingIterator 8 Deprecated: Creation of dynamic property WrappedIterator::$index is deprecated in /in/UIfIb on line 73 Creating WrappingIterator 9 Deprecated: Creation of dynamic property WrappedIterator::$index is deprecated in /in/UIfIb on line 73 Creating WrappingIterator 10 Destroying WrappedIterator 6 Destroying WrappingIterator 6 Destroying WrappingIterator 5 Destroying WrappedIterator 7 Destroying WrappingIterator 7 Destroying WrappedIterator 8 Destroying WrappingIterator 8 Destroying WrappedIterator 9 Destroying WrappingIterator 9 Destroying WrappedIterator 5 Deprecated: Creation of dynamic property WrappedIterator::$index is deprecated in /in/UIfIb on line 73 Creating WrappingIterator 11 Deprecated: Creation of dynamic property WrappedIterator::$index is deprecated in /in/UIfIb on line 73 Creating WrappingIterator 12 Deprecated: Creation of dynamic property WrappedIterator::$index is deprecated in /in/UIfIb on line 73 Creating WrappingIterator 13 Deprecated: Creation of dynamic property WrappedIterator::$index is deprecated in /in/UIfIb on line 73 Creating WrappingIterator 14 Deprecated: Creation of dynamic property WrappedIterator::$index is deprecated in /in/UIfIb on line 73 Creating WrappingIterator 15 Destroying WrappedIterator 11 Destroying WrappingIterator 11 Destroying WrappingIterator 10 Destroying WrappedIterator 12 Destroying WrappingIterator 12 Destroying WrappedIterator 13 Destroying WrappingIterator 13 Destroying WrappedIterator 14 Destroying WrappingIterator 14 Destroying WrappedIterator 10 Deprecated: Creation of dynamic property WrappedIterator::$index is deprecated in /in/UIfIb on line 73 Creating WrappingIterator 16 Deprecated: Creation of dynamic property WrappedIterator::$index is deprecated in /in/UIfIb on line 73 Creating WrappingIterator 17 Deprecated: Creation of dynamic property WrappedIterator::$index is deprecated in /in/UIfIb on line 73 Creating WrappingIterator 18 Deprecated: Creation of dynamic property WrappedIterator::$index is deprecated in /in/UIfIb on line 73 Creating WrappingIterator 19 Deprecated: Creation of dynamic property WrappedIterator::$index is deprecated in /in/UIfIb on line 73 Creating WrappingIterator 20 Destroying WrappedIterator 16 Destroying WrappingIterator 16 Destroying WrappingIterator 15 Destroying WrappedIterator 17 Destroying WrappingIterator 17 Destroying WrappedIterator 18 Destroying WrappingIterator 18 Destroying WrappedIterator 19 Destroying WrappingIterator 19 Destroying WrappedIterator 15 Done Starting run with class "DestroyingIterator" and limit "20" Destroying WrappingIterator 20 Destroying WrappedIterator 20 Deprecated: Creation of dynamic property WrappedIterator::$index is deprecated in /in/UIfIb on line 73 Creating DestroyingIterator 1 Deprecated: Creation of dynamic property WrappedIterator::$index is deprecated in /in/UIfIb on line 73 Creating DestroyingIterator 2 Deprecated: Creation of dynamic property WrappedIterator::$index is deprecated in /in/UIfIb on line 73 Creating DestroyingIterator 3 Deprecated: Creation of dynamic property WrappedIterator::$index is deprecated in /in/UIfIb on line 73 Creating DestroyingIterator 4 Deprecated: Creation of dynamic property WrappedIterator::$index is deprecated in /in/UIfIb on line 73 Creating DestroyingIterator 5 Destroying WrappedIterator 1 Destroying DestroyingIterator 1 Destroying WrappedIterator 2 Destroying DestroyingIterator 2 Destroying WrappedIterator 3 Destroying DestroyingIterator 3 Destroying WrappedIterator 4 Destroying DestroyingIterator 4 Deprecated: Creation of dynamic property WrappedIterator::$index is deprecated in /in/UIfIb on line 73 Creating DestroyingIterator 6 Deprecated: Creation of dynamic property WrappedIterator::$index is deprecated in /in/UIfIb on line 73 Creating DestroyingIterator 7 Deprecated: Creation of dynamic property WrappedIterator::$index is deprecated in /in/UIfIb on line 73 Creating DestroyingIterator 8 Deprecated: Creation of dynamic property WrappedIterator::$index is deprecated in /in/UIfIb on line 73 Creating DestroyingIterator 9 Deprecated: Creation of dynamic property WrappedIterator::$index is deprecated in /in/UIfIb on line 73 Creating DestroyingIterator 10 Destroying WrappedIterator 6 Destroying DestroyingIterator 6 Destroying DestroyingIterator 5 Destroying WrappedIterator 5 Destroying WrappedIterator 7 Destroying DestroyingIterator 7 Destroying WrappedIterator 8 Destroying DestroyingIterator 8 Destroying WrappedIterator 9 Destroying DestroyingIterator 9 Deprecated: Creation of dynamic property WrappedIterator::$index is deprecated in /in/UIfIb on line 73 Creating DestroyingIterator 11 Deprecated: Creation of dynamic property WrappedIterator::$index is deprecated in /in/UIfIb on line 73 Creating DestroyingIterator 12 Deprecated: Creation of dynamic property WrappedIterator::$index is deprecated in /in/UIfIb on line 73 Creating DestroyingIterator 13 Deprecated: Creation of dynamic property WrappedIterator::$index is deprecated in /in/UIfIb on line 73 Creating DestroyingIterator 14 Deprecated: Creation of dynamic property WrappedIterator::$index is deprecated in /in/UIfIb on line 73 Creating DestroyingIterator 15 Destroying WrappedIterator 11 Destroying DestroyingIterator 11 Destroying DestroyingIterator 10 Destroying WrappedIterator 10 Destroying WrappedIterator 12 Destroying DestroyingIterator 12 Destroying WrappedIterator 13 Destroying DestroyingIterator 13 Destroying WrappedIterator 14 Destroying DestroyingIterator 14 Deprecated: Creation of dynamic property WrappedIterator::$index is deprecated in /in/UIfIb on line 73 Creating DestroyingIterator 16 Deprecated: Creation of dynamic property WrappedIterator::$index is deprecated in /in/UIfIb on line 73 Creating DestroyingIterator 17 Deprecated: Creation of dynamic property WrappedIterator::$index is deprecated in /in/UIfIb on line 73 Creating DestroyingIterator 18 Deprecated: Creation of dynamic property WrappedIterator::$index is deprecated in /in/UIfIb on line 73 Creating DestroyingIterator 19 Deprecated: Creation of dynamic property WrappedIterator::$index is deprecated in /in/UIfIb on line 73 Creating DestroyingIterator 20 Destroying WrappedIterator 16 Destroying DestroyingIterator 16 Destroying DestroyingIterator 15 Destroying WrappedIterator 15 Destroying WrappedIterator 17 Destroying DestroyingIterator 17 Destroying WrappedIterator 18 Destroying DestroyingIterator 18 Destroying WrappedIterator 19 Destroying DestroyingIterator 19 Done Destroying WrappedIterator 20 Destroying DestroyingIterator 20

This tab shows result from various feature-branches currently under review by the php developers. Contact me to have additional branches featured.

Active branches

Archived branches

Once feature-branches are merged or declined, they are no longer available. Their functionality (when merged) can be viewed from the main output page


preferences:
33.56 ms | 437 KiB | 5 Q