php-src/Zend/tests/first_class_callable/constexpr/autoload.phpt
Tim Düsterhus 2042fd34e0
Support first-class callables in const-expressions (#17213)
RFC: https://wiki.php.net/rfc/fcc_in_const_expr

Co-authored-by: Volker Dusch <volker@tideways-gmbh.com>
2025-02-20 18:52:47 +01:00

31 lines
651 B
PHP

--TEST--
FCC in const expression triggers autoloader.
--FILE--
<?php
spl_autoload_register(static function ($class) {
echo "Autoloading {$class}", PHP_EOL;
eval(
<<<'EOT'
class AutoloadedClass {
public static function withStaticMethod() {
echo "Called ", __METHOD__, PHP_EOL;
}
}
EOT
);
});
const Closure = AutoloadedClass::withStaticMethod(...);
var_dump(Closure);
(Closure)();
?>
--EXPECTF--
Autoloading AutoloadedClass
object(Closure)#%d (1) {
["function"]=>
string(16) "withStaticMethod"
}
Called AutoloadedClass::withStaticMethod