<?php
function test($test) {
return new class($test) {
public function __construct(public $test) {}
};
}
function test3($test) {
return eval("return new class($test) {
public function __construct(public \$test) {}};"
);
}
function compare($a, $b) {
var_dump([
$a == $b,
$a === $b,
get_class($a) == get_class($b),
]);
}
compare(test(1), test(1)); // true, false, true,
compare(test3(1), test3(1)); // false, false, false,
- Output for 8.1.32, 8.2.0 - 8.2.29, 8.3.0 - 8.3.25, 8.4.1 - 8.4.12
- array(3) {
[0]=>
bool(true)
[1]=>
bool(false)
[2]=>
bool(true)
}
array(3) {
[0]=>
bool(false)
[1]=>
bool(false)
[2]=>
bool(false)
}
preferences:
50.17 ms | 406 KiB | 5 Q