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)); var_dump($products); foreach($products as $key=>$value) { echo $value; }
based on 1TX0h
Output for 7.1.0 - 7.2.0
array(5) { [0]=> object(Products)#1 (2) { ["chemID"]=> int(1) ["catID"]=> int(1) } [1]=> object(Products)#2 (2) { ["chemID"]=> int(1) ["catID"]=> int(1) } [2]=> object(Products)#3 (2) { ["chemID"]=> int(2) ["catID"]=> int(2) } [3]=> object(Products)#4 (2) { ["chemID"]=> int(3) ["catID"]=> int(3) } [4]=> object(Products)#5 (2) { ["chemID"]=> int(4) ["catID"]=> int(4) } } Recoverable fatal error: Object of class Products could not be converted to string in /in/qYKOY on line 21
Process exited with code 255.
Output for 5.3.19 - 7.0.20
array(5) { [0]=> object(Products)#1 (2) { ["chemID"]=> int(1) ["catID"]=> int(1) } [1]=> object(Products)#2 (2) { ["chemID"]=> int(1) ["catID"]=> int(1) } [2]=> object(Products)#3 (2) { ["chemID"]=> int(2) ["catID"]=> int(2) } [3]=> object(Products)#4 (2) { ["chemID"]=> int(3) ["catID"]=> int(3) } [4]=> object(Products)#5 (2) { ["chemID"]=> int(4) ["catID"]=> int(4) } } Catchable fatal error: Object of class Products could not be converted to string in /in/qYKOY on line 21
Process exited with code 255.