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']) && isset($pobj['chemID'])) { if(isset($carray['catID']) && isset($pobj['catID']) && $carray['catID']==$pobj['catID']) { $cnt++; } } } } echo $cnt;
based on dpmuh
Output for 7.0.0 - 7.2.0
Fatal error: Uncaught Error: Cannot use object of type Products as array in /in/pNYoU:22 Stack trace: #0 {main} thrown in /in/pNYoU on line 22
Process exited with code 255.
Output for 5.3.19 - 5.6.28
Fatal error: Cannot use object of type Products as array in /in/pNYoU on line 22
Process exited with code 255.