3v4l.org

run code in 300+ PHP versions simultaneously
<?php class Foo { private $resource; private $state = 'stable'; public function runBar() { try { $this->bar(); } catch (\Exception $e) { // Instead of trying to make this object stable again, just.. yield; } } private function bar() { $this->state = 'unstable'; $this->resource = 'Some external service'; throw new \Exception('Something went wrong with our resource, we\'re now in an unstable state'); } } $foo = new Foo(); $foo->runBar(); var_dump($foo);

preferences:
26.73 ms | 404 KiB | 5 Q