3v4l.org

run code in 300+ PHP versions simultaneously
<?php //EXAMPLE, PSEUDO CODE class Cart{ protected $items = [];//array of id => [stuff] public function __construct(){ $this->read(); } //$attributes - IDK, maybe quantity or ... something... public function add(int $id, array $attributes = []){ if(isset($this->items [$id])){ //@todo - do smth about it... } $this->items [$id][] = $attributes; return $this; } public function read(){ //might change this later, to db and or serialization $this->items = json_decode((isset($_SESSION['cart']))); return $this; } public function write(){ //might change this later, to db and or serialization $_SESSION['cart'] = json_encode($this->items); return $this; } public function getItems(){ return $this->items; } } /// //thing is you don't care HERE about internal implementaion. Which can be changed later. $cart = new Cart(); $cart->add(17,['quantity' => 12]); $cart->add(42,['quantity' => 99])->write(); var_dump($cart->getItems());
Output for git.master, git.master_jit, rfc.property-hooks
array(2) { [17]=> array(1) { [0]=> array(1) { ["quantity"]=> int(12) } } [42]=> array(1) { [0]=> array(1) { ["quantity"]=> int(99) } } }

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