mirror of
https://github.com/php/php-src.git
synced 2025-08-17 22:48:57 +02:00

* Include the source location in Closure names This change makes stack traces involving Closures, especially multiple different Closures, much more useful, because it's more easily visible *which* closure was called for a given stack frame. The implementation is similar to that of anonymous classes which already include the file name and line number within their generated classname. * Update scripts/dev/bless_tests.php for closure naming * Adjust existing tests for closure naming * Adjust tests for closure naming that were not caught locally * Drop the namespace from closure names This is redundant with the included filename. * Include filename and line number as separate keys in Closure debug info * Fix test * Fix test * Include the surrounding class and function name in closure names * Fix test * Relax test expecations * Fix tests after merge * NEWS / UPGRADING
112 lines
2.1 KiB
PHP
112 lines
2.1 KiB
PHP
--TEST--
|
|
ReflectionFiber basic tests
|
|
--FILE--
|
|
<?php
|
|
|
|
$callable = function (): void {
|
|
$reflection = new ReflectionFiber(Fiber::getCurrent());
|
|
echo "\nWithin Fiber:\n";
|
|
var_dump($reflection->getExecutingFile());
|
|
var_dump($reflection->getExecutingLine());
|
|
var_dump($reflection->getTrace());
|
|
Fiber::suspend();
|
|
};
|
|
|
|
$fiber = new Fiber($callable);
|
|
|
|
$reflection = new ReflectionFiber($fiber);
|
|
|
|
echo "Before Start:\n";
|
|
var_dump($fiber === $reflection->getFiber());
|
|
var_dump($callable === $reflection->getCallable());
|
|
|
|
$fiber->start();
|
|
|
|
echo "\nAfter Start:\n";
|
|
var_dump($reflection->getExecutingFile());
|
|
var_dump($reflection->getExecutingLine());
|
|
var_dump($callable === $reflection->getCallable());
|
|
var_dump($reflection->getTrace());
|
|
|
|
$fiber->resume();
|
|
|
|
echo "\nAfter Resume:\n";
|
|
$reflection->getTrace();
|
|
|
|
?>
|
|
--EXPECTF--
|
|
Before Start:
|
|
bool(true)
|
|
bool(true)
|
|
|
|
Within Fiber:
|
|
string(%d) "%sReflectionFiber_basic.php"
|
|
int(7)
|
|
array(2) {
|
|
[0]=>
|
|
array(7) {
|
|
["file"]=>
|
|
string(%d) "%sReflectionFiber_basic.php"
|
|
["line"]=>
|
|
int(8)
|
|
["function"]=>
|
|
string(8) "getTrace"
|
|
["class"]=>
|
|
string(15) "ReflectionFiber"
|
|
["object"]=>
|
|
object(ReflectionFiber)#4 (0) {
|
|
}
|
|
["type"]=>
|
|
string(2) "->"
|
|
["args"]=>
|
|
array(0) {
|
|
}
|
|
}
|
|
[1]=>
|
|
array(2) {
|
|
["function"]=>
|
|
string(%d) "{closure:%s:%d}"
|
|
["args"]=>
|
|
array(0) {
|
|
}
|
|
}
|
|
}
|
|
|
|
After Start:
|
|
string(%d) "%sReflectionFiber_basic.php"
|
|
int(9)
|
|
bool(true)
|
|
array(2) {
|
|
[0]=>
|
|
array(6) {
|
|
["file"]=>
|
|
string(%d) "%sReflectionFiber_basic.php"
|
|
["line"]=>
|
|
int(9)
|
|
["function"]=>
|
|
string(7) "suspend"
|
|
["class"]=>
|
|
string(5) "Fiber"
|
|
["type"]=>
|
|
string(2) "::"
|
|
["args"]=>
|
|
array(0) {
|
|
}
|
|
}
|
|
[1]=>
|
|
array(2) {
|
|
["function"]=>
|
|
string(%d) "{closure:%s:%d}"
|
|
["args"]=>
|
|
array(0) {
|
|
}
|
|
}
|
|
}
|
|
|
|
After Resume:
|
|
|
|
Fatal error: Uncaught Error: Cannot fetch information from a fiber that has not been started or is terminated in %sReflectionFiber_basic.php:%d
|
|
Stack trace:
|
|
#0 %sReflectionFiber_basic.php(%d): ReflectionFiber->getTrace()
|
|
#1 {main}
|
|
thrown in %sReflectionFiber_basic.php on line %d
|