3v4l.org

run code in 300+ PHP versions simultaneously
<?php class Manufacturer{ protected $_name; public function setManufacturerName($name){ $this->_name = $name; } public function getManufacturerName(){ return $this->_name; } } class Product{ protected $_title; protected $_category; protected $_manufacturer; public function __construct(){ $this->_manufacturer = new Manufacturer(); } public function getCategory(){ return $this->_category; } public function getTitle(){ return $this->_title; } public function setManufacturerName($name){ $this->_manufacturer->setManufacturerName($name); } public function __clone(){ $this->_manufacturer = clone $this->_manufacturer; } // with use of this magic method __clone() it will echo: CD Brahms is made by Producent A public function getManufacturerName(){ return $this->_manufacturer->getManufacturerName(); } } class Order extends Product{ protected $_price; protected $_deliver; public function __construct($title, $category, $price){ parent::__construct(); $this->_title = $title; $this->_category = $category; $this->_price = $price; $this->doWeDeliver(); } public function setTitle($title){ $this->_title = $title; } public function getPrice(){ return $this->_price; } public function getDeliver(){ return $this->_deliver; } protected function doWeDeliver(){ $this->_deliver = $this->_price > 30 ? "Yes" : "No" ; } public function displaySentence(){ echo "Product: ".$this->_title." Category: ".$this->_category." Prijs: ".$this->_price." Gratis bezorging: ".$this->_deliver; } } $order = new Order("CD Brahms", "Media", "45"); $order->setManufacturerName("Producent A"); echo $order->getTitle()." is made by ". $order->getManufacturerName()."<br />"; // CD Brahms is made by Producent A $order2 = clone $order; $order2->setTitle("Second title"); $order2->setManufacturerName("Producent B"); echo $order2->getTitle()." is made by ". $order2->getManufacturerName()."<br />"; // Second title is made by Producent B echo $order->getTitle()." is made by ". $order->getManufacturerName()."<br />"; // CD Brahms is made by Producent B CD Brahms is made by Producent A with use of __clone()
Output for git.master, git.master_jit, rfc.property-hooks
CD Brahms is made by Producent A<br />Second title is made by Producent B<br />CD Brahms is made by Producent A<br />

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