3v4l.org

run code in 300+ PHP versions simultaneously
<?php class Products{ protected $_title; protected $_category; protected $_price; public function __construct($title, $category, $price){ if($price < 0){ throw new Exception('Price must be a positive number'); } $this->_title = $title; $this->_category = $category; $this->_price = $price; } public function getPrice(){ return $this->_price; } } try{ $product = new Products('Title', 'Category', -45); echo $product->getPrice(); } catch(Exception $e){ echo 'Caught exception: ', $e->getMessage(), "\n"; echo 'Caught exception: ', $e->getCode(), "\n"; echo 'Caught exception: ', $e->getFile(), "\n"; echo 'Caught exception: ', $e->getLine(), "\n"; echo 'Caught exception: ', $e->getTrace(), "\n"; echo 'Caught exception: ', $e->getTraceAsString(), "\n"; echo 'Caught exception: ', $e, "\n"; }
Output for git.master, git.master_jit, rfc.property-hooks
Caught exception: Price must be a positive number Caught exception: 0 Caught exception: /in/uJ6Xn Caught exception: 11 Caught exception: Warning: Array to string conversion in /in/uJ6Xn on line 34 Array Caught exception: #0 /in/uJ6Xn(26): Products->__construct('Title', 'Category', -45) #1 {main} Caught exception: Exception: Price must be a positive number in /in/uJ6Xn:11 Stack trace: #0 /in/uJ6Xn(26): Products->__construct('Title', 'Category', -45) #1 {main}

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:
40.57 ms | 402 KiB | 8 Q