<?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;
}
- Output for 7.4.0 - 7.4.33, 8.0.0 - 8.0.30, 8.1.0 - 8.1.27, 8.2.0 - 8.2.17, 8.3.0 - 8.3.4
- 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)
}
}
Fatal error: Uncaught Error: Object of class Products could not be converted to string in /in/qYKOY:21
Stack trace:
#0 {main}
thrown in /in/qYKOY on line 21
Process exited with code 255. - Output for 7.1.0 - 7.1.25, 7.2.0 - 7.2.33, 7.3.0 - 7.3.33
- 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.5.24 - 5.5.35, 5.6.8 - 5.6.28, 7.0.0 - 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.
preferences:
171.64 ms | 402 KiB | 194 Q