3v4l.org

run code in 200+ php & hhvm versions
Bugs & Features
<?php $products = array(); class Products { public $chemID; public $catID; } $prod1 = new Products; $prod1->chemID=1; $prod1->catID=1; array_push($products,$prod1); for($i = 1; $i < 5; $i++) { ${'prod'.$i} = new Products; ${'prod'.$i}->chemID = $i; ${'prod'.$i}->catID = $i; array_push($products,${'prod'.$i}); } $carts = (object)array(array("chemID"=> 1, "catID" => 4),array("chemID"=> 2, "catID" => 4), array("chemID"=> 1, "catID" => 1)); $cnt = 0; foreach($products as $pkey=>$pobj) { foreach($carts as $ckey=>$carray) { if(isset($carray['chemID']) && $carray['chemID']==$pobj['chemID']) { if(isset($carray['catID']) && $carray['catID']==$pobj['catID']) { $cnt++; } } } } echo $cnt;
based on pNYoU

Shows result from various feature-branches currently under review from the php developers. Contact me to have additional branches featured.

Output for Typed properties v2
Fatal error: Uncaught Error: Cannot use object of type Products as array in /in/sHri3:22 Stack trace: #0 {main} thrown in /in/sHri3 on line 22
Output for Arrow functions
Fatal error: Uncaught Error: Cannot use object of type Products as array in /in/sHri3:22 Stack trace: #0 {main} thrown in /in/sHri3 on line 22
Output for Object typehint
Fatal error: Uncaught Error: Cannot use object of type Products as array in /in/sHri3:22 Stack trace: #0 {main} thrown in /in/sHri3 on line 22
Output for Array change keys
Fatal error: Uncaught Error: Cannot use object of type Products as array in /in/sHri3:22 Stack trace: #0 {main} thrown in /in/sHri3 on line 22
Output for Lexical anon
Fatal error: Cannot use object of type Products as array in /in/sHri3 on line 22

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