3v4l.org

run code in 300+ PHP versions simultaneously
<?php class Foo { private $value = 42; public function property( $value = null ) { $ret = $this->value; if ( func_num_args() === 0 ) { echo "Called as getter!\n"; } else { echo "Called as setter!\n"; $this->value = $value; } return $ret; } } $foo = new Foo; echo "Calling as getter...\n"; var_dump( $foo->property() ); echo "Calling as setter...\n"; var_dump( $foo->property( 123 ) ); echo "Calling as setter, passing null...\n"; var_dump( $foo->property( null ) ); echo "Calling as getter...\n"; var_dump( $foo->property() );

preferences:
15.88 ms | 404 KiB | 5 Q