3v4l.org

run code in 300+ PHP versions simultaneously
<?php class ConstructorException extends Exception {} class Foo extends ArrayObject { public function __construct( $arr = array(), $flags = 0, $iterator = 'FooIterator' ) { parent::__construct( $arr, $flags, $iterator ); } /** * @return ArrayIterator */ public function getIterator() { $class = $this->getIteratorClass(); return new $class($this); } } class FooIterator extends ArrayIterator { function __construct( $array = array(), $flags = 0 ) { unset( $array[0] , $array[1] ); parent::__construct( $array, $flags ); } } try { $f = new Foo( array( 1, 2, 3 ) ); $it = $f->getIterator(); $it->offsetSet(5, 10); $f[7] = 11; while ($it->valid()) { echo $it->key() . ' => ' . $it->current() . "\n"; $it->next(); } if ( get_class( $it ) !== 'FooIterator' ) { throw new Exception( 'Expected iterator to be FooIterator.' ); } die( "FAIL\n" ); } catch ( ConstructorException $e ) { die( "PASS\n" ); } catch ( \Exception $e ) { die( sprintf( "ERROR: %s\n", $e->getMessage() ) ); }
Output for git.master, git.master_jit, rfc.property-hooks
Deprecated: Return type of Foo::getIterator() should either be compatible with ArrayObject::getIterator(): Iterator, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /in/R8PHr on line 14 2 => 3 5 => 10 7 => 11 FAIL

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:
175.48 ms | 406 KiB | 5 Q