3v4l.org

run code in 300+ PHP versions simultaneously
<?php class Foo { protected string $property; public function __construct(string $property) { $this->property = $property; } public function getProperty(): string { return $this->property; } } $foo = new Foo("foo"); echo "Default value:\n"; var_dump($foo->getProperty()); echo "\nInvoking the __constructor() method again:\n"; $foo->__construct("baz"); var_dump($foo->getProperty()); // https://ocramius.github.io/blog/accessing-private-php-class-members-without-reflection/ echo "\nClosure binding:\n"; Closure::bind( function (): void { $this->property = "bang"; }, $foo, $foo )->__invoke(); var_dump($foo->getProperty()); echo "\nAbusing anonymous classes:\n"; $fooAbuser = new class("") extends Foo { public function abuse(Foo $foo): Foo { $foo->property = "boom"; return $foo; } }; var_dump($fooAbuser->abuse($foo)->getProperty());
Output for git.master, git.master_jit, rfc.property-hooks
Default value: string(3) "foo" Invoking the __constructor() method again: string(3) "baz" Closure binding: string(4) "bang" Abusing anonymous classes: string(4) "boom"

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:
60.66 ms | 401 KiB | 8 Q