3v4l.org

run code in 300+ PHP versions simultaneously
<?php /** * * @author Kyle @ Iezon * @copyright (c) 2016 - 2017, Iezon * * Controller for Tax and Payments * **/ namespace Iezon\Products; class Item { public function __construct($product_id) { // load product from database } public function cost() { return 1000; } } class TaxReturn { const Tax = 0.2; const TaxPercent = 20; private $_total = 0; private $_item = []; public function __construct() { $stored = $_SESSION['total']; if(empty($stored)) return; $this->_total = $stored; } public function append(Item $item) { $this->_item[] = $item; $this->_total = $this->_total + $item->cost(); return $this; } public function retrieve() { return [ 'total' => $this->_total, 'tax_total' => (($this->_total / 100) * self::Tax) + $this->_total ]; } } session_start(); $iezon = []; $iezon['payment'] = [ 'object' => new TaxReturn(), 'disclose' => [] ]; $iezon['payment']['object']->append(new Item('Some Id')); $iezon['payment']['disclose'] = $iezon['payment']['object']->retrieve(); echo 'Total (' . TaxReturn::TaxPercent . '%) : ' . $iezon['payment']['disclose']['tax_total'];
Output for 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
Warning: Undefined array key "total" in /in/YNJlJ on line 35 Total (20%) : 1002
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 Warning: Undefined array key "total" in /in/YNJlJ on line 35 Total (20%) : 1002
Output for 5.6.0 - 5.6.40, 7.0.0 - 7.0.33, 7.1.0 - 7.1.33, 7.2.0 - 7.2.33, 7.3.0 - 7.3.31, 7.4.0 - 7.4.33
Notice: Undefined index: total in /in/YNJlJ on line 35 Total (20%) : 1002
Output for 7.3.32 - 7.3.33
Total (20%) : 1002

preferences:
239.81 ms | 401 KiB | 288 Q