3v4l.org

run code in 300+ PHP versions simultaneously
<?php class Cart { public function save(object $repo = null) { if ($repo === null || !$repo instanceof CartRepository) { throw new Exception('Save the cart using the CartRepository' . "\n"); } $repo->save($this); } } class CartRepository { public function save(Cart $cart) { return 'saved!'; } } $repo = new CartRepository(); $cart = new Cart(); try { $cart->save(); } catch (Exception $e) { echo $e->getMessage(); } echo $repo->save($cart);
Output for git.master, git.master_jit
Deprecated: Implicitly marking parameter $repo as nullable is deprecated, the explicit nullable type must be used instead in /in/uHW1e on line 5 Save the cart using the CartRepository saved!
Output for rfc.property-hooks
Save the cart using the CartRepository saved!

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