1
0
mirror of https://github.com/php/php-src.git synced 2026-03-24 00:02:20 +01:00
Files
archived-php-src/Zend/tests/closures/closure_get_current.phpt
Ilija Tovilo eb65ec41b7 Implement Closure::getCurrent() to retrieve current closure
Fixes GH-18163
Closes GH-18167
2025-07-21 16:07:49 +02:00

65 lines
719 B
PHP

--TEST--
Closure::getCurrent()
--FILE--
<?php
$i = 1;
$c = function ($p) use (&$i) {
$self = Closure::getCurrent();
var_dump($p, $i);
$i++;
if ($p < 10) {
$self($p + 1);
}
};
$c(1);
var_dump($i);
function fail() {
Closure::getCurrent();
}
try {
fail();
} catch (Error $e) {
echo $e->getMessage(), "\n";
}
function foo() {
var_dump(Closure::getCurrent());
}
try {
foo(...)();
} catch (Error $e) {
echo $e->getMessage(), "\n";
}
?>
--EXPECT--
int(1)
int(1)
int(2)
int(2)
int(3)
int(3)
int(4)
int(4)
int(5)
int(5)
int(6)
int(6)
int(7)
int(7)
int(8)
int(8)
int(9)
int(9)
int(10)
int(10)
int(11)
Current function is not a closure
Current function is not a closure