3v4l.org

run code in 300+ PHP versions simultaneously
<?php class ShopProduct { public $discount = 0; public $title; public $producerMainName; public $producerFirstName; protected $price; function __construct($title, $firstName, $mainName, $price) { $this->title = $title; $this->producerFirstName = $firstName; $this->producerMainName = $mainName; $this->price = $price; } function getSummaryLine(){ $base = "{$this->title} ( {$this->producerMainName}, "; $base .= "{$this->producerFirstName} )"; return $base; } function getProducer() { return "{$this->producerFirstName} " . "{$this->producerMainName}"; } function setDiscount(){ $this->discount=$num; } public function getPrice() { # code... return ($this->price - $this->discount); } } class ShopProductWriter(){ private $products = array(); public function addProduct( ShopProduct $shopProduct){ $this->product[] = $shopProduct; } public function write(){ $str = ""; foreach ($this->products as $shopProduct) { $str .= "{$shopProduct->title}: "; $str .= "{$shopProduct->getProducer()}"; $str .= "{$shopProduct->getPrice()}\n"; } print $str; } } class CDProduct extends ShopProduct { public $playLength; function __construct($title, $firstName, $mainName, $price, $playLength){ parent::__construct($title, $firstName, $mainName, $price); $this->playLength = $playLength; } function getPlayLength(){ return $this->playLength; } function getSummaryLine(){ $base = parent::getSummaryLine(); $base .= " :Legth of song {$this->playLength}"; return $base; } } class BookProduct extends shopProduct{ public $numPages; function __construct($title, $firstName, $mainName, $price, $numPages){ parent::__construct($title, $firstName, $mainName, $price); $this->playLength = $playLength; } function getSummaryLine(){ $base = parent::getSummaryLine(); $base .= ": Number of pages - {$this->numPages}"; } function getProducer() { return "{$this->producerFirstName} " . "{$this->producerMainName}"; } function getPrice(){ return $this->price; } } $product2 = new CDProduct("On my own", "Ashes", "Remain", 10.99, 2.53); $product3 = new CDProduct("On my own", "Ashes", "Remain", 10.99, 2.53); $product4 = new CDProduct("On my own", "Ashes", "Remain", 10.99, 2.53); $product5 = new CDProduct("On my own", "Ashes", "Remain", 10.99, 2.53); print write();

Here you find the average performance (time & memory) of each version. A grayed out version indicates it didn't complete successfully (based on exit-code).

VersionSystem time (s)User time (s)Memory (MiB)
7.0.20.0270.05020.27
7.0.10.0100.08720.23
7.0.00.0070.04020.07
5.6.170.0300.05020.56
5.6.160.0030.09020.71
5.6.150.0100.07318.27
5.6.140.0070.04718.18
5.6.130.0070.05718.21
5.6.120.0130.08021.00
5.6.110.0130.08321.02
5.6.100.0130.07321.03
5.6.90.0130.07721.01
5.6.80.0030.06720.36
5.5.310.0230.08020.32
5.5.300.0030.04318.04
5.5.290.0000.05017.95
5.5.280.0000.05020.66
5.5.270.0130.04320.90
5.5.260.0030.08020.70
5.5.250.0030.07320.63
5.5.240.0300.06020.13

preferences:
143.32 ms | 1394 KiB | 7 Q