1
0
mirror of https://github.com/php/php-src.git synced 2026-03-24 08:12:21 +01:00
Files
archived-php-src/Zend/tests/closures/closure_const_expr/static_variable.phpt
Tim Düsterhus 45d1acf916 Zend: Fix reference counting for Closures in const-expr (#17853)
* Clean up closure static variable handling

* Zend: Fix reference counting for Closures in const-expr

Fixes php/php-src#17851

---------

Co-authored-by: Ilija Tovilo <ilija.tovilo@me.com>
2025-03-27 10:11:44 +01:00

78 lines
940 B
PHP

--TEST--
Closures in const expressions support static variables.
--FILE--
<?php
const Closure = static function () {
static $x = [];
static $i = 1;
$i *= 2;
$x[] = $i;
var_dump($x);
};
var_dump(Closure);
(Closure)();
(Closure)();
(Closure)();
var_dump(Closure);
?>
--EXPECTF--
object(Closure)#%d (4) {
["name"]=>
string(%d) "{closure:%s:%d}"
["file"]=>
string(%d) "%s"
["line"]=>
int(3)
["static"]=>
array(2) {
["x"]=>
array(0) {
}
["i"]=>
int(1)
}
}
array(1) {
[0]=>
int(2)
}
array(2) {
[0]=>
int(2)
[1]=>
int(4)
}
array(3) {
[0]=>
int(2)
[1]=>
int(4)
[2]=>
int(8)
}
object(Closure)#%d (4) {
["name"]=>
string(%d) "{closure:%s:%d}"
["file"]=>
string(%d) "%s"
["line"]=>
int(3)
["static"]=>
array(2) {
["x"]=>
array(3) {
[0]=>
int(2)
[1]=>
int(4)
[2]=>
int(8)
}
["i"]=>
int(8)
}
}