3v4l.org

run code in 300+ PHP versions simultaneously
<?php class Product { protected $price; protected $discount; public function getPrice() { return $this->price->getValue(); } public function setPrice($price, $type) { $this->price = new Price($price); $this->price->setType($type); } public function getDiscount() { return $this->discount->getValue(); } public function setDiscount($discount, $type) { $this->discount = new Discount($discount); $this->discount->setType($type); } } class Price { protected $type; // 0 - one-off price, 1 - monthly price, 2 - combination of previous two; protected $value; function __construct($value) { if (is_numeric($value)) { $this->value = round(floatval($value), 2); } else { $this->value = 0; } } public function getType() { return $this->type; } public function setType($type) { if (is_numeric($type) && in_array(intval($type), array(0, 1, 2))) { $this->type = intval($type); } else { $this->type = 0; } } public function getValue() { return $this->value; } } class Discount extends Price{} class Shopcart { protected $shopping_list; function __construct($products) { $this->shopping_list[] = $products; } public function getTotalPrice() { $cost = 0; foreach ($this->shopping_list as $item) { $cost += $item->getCost(); } return $cost; } }
Output for 5.4.2 - 5.4.45, 5.5.24 - 5.5.35, 5.6.7 - 5.6.28, 7.0.0 - 7.0.20, 7.1.0 - 7.1.20, 7.2.6 - 7.2.33, 7.3.16 - 7.3.33, 7.4.0 - 7.4.33, 8.0.0 - 8.0.30, 8.1.0 - 8.1.28, 8.2.0 - 8.2.18, 8.3.0 - 8.3.4, 8.3.6
Output for 8.3.5
Warning: PHP Startup: Unable to load dynamic library 'sodium.so' (tried: /usr/lib/php/8.3.5/modules/sodium.so (libsodium.so.23: cannot open shared object file: No such file or directory), /usr/lib/php/8.3.5/modules/sodium.so.so (/usr/lib/php/8.3.5/modules/sodium.so.so: cannot open shared object file: No such file or directory)) in Unknown on line 0

preferences:
188.73 ms | 402 KiB | 225 Q