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());

preferences:
48.67 ms | 402 KiB | 5 Q