php-src/Zend/tests/first_class_callable/constexpr/namespace_004.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

68 lines
1.1 KiB
PHP

--TEST--
Allow defining FCC in const expressions in a namespace with function matching a global function later.
--FILE--
<?php
namespace Foo;
function foo(\Closure $c = strrev(...)) {
$d = strrev(...);
var_dump($c);
var_dump($c("abc"));
var_dump($d);
var_dump($d("abc"));
}
foo();
if (random_int(1, 2) > 0) {
function strrev(string $value) {
return 'not the global one';
}
}
foo();
?>
--EXPECTF--
object(Closure)#1 (2) {
["function"]=>
string(6) "strrev"
["parameter"]=>
array(1) {
["$string"]=>
string(10) "<required>"
}
}
string(3) "cba"
object(Closure)#2 (2) {
["function"]=>
string(6) "strrev"
["parameter"]=>
array(1) {
["$string"]=>
string(10) "<required>"
}
}
string(3) "cba"
object(Closure)#2 (2) {
["function"]=>
string(6) "strrev"
["parameter"]=>
array(1) {
["$string"]=>
string(10) "<required>"
}
}
string(3) "cba"
object(Closure)#1 (2) {
["function"]=>
string(6) "strrev"
["parameter"]=>
array(1) {
["$string"]=>
string(10) "<required>"
}
}
string(3) "cba"