<?php
namespace work;
class Test1 {}
$a = (object)[];
$b = new \stdClass();
$data = [$a, $b, new Test1()];
$result = json_encode($data);
var_dump($result);
echo str_repeat('-', 100) . PHP_EOL;
$result1 = json_decode($result);
$result2 = json_decode($result, true);
$result1_1 = json_encode($result1);
$result2_1 = json_encode($result2);
var_dump($result1_1, $result2_1);
- Output for 8.1.0 - 8.1.33, 8.2.0 - 8.2.29, 8.3.0 - 8.3.25, 8.4.1 - 8.4.12
- string(10) "[{},{},{}]"
----------------------------------------------------------------------------------------------------
string(10) "[{},{},{}]"
string(10) "[[],[],[]]"
preferences:
63.79 ms | 406 KiB | 5 Q