|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
[2020-04-08 16:46 UTC] daverandom@php.net
-Status: Open
+Status: Not a bug
[2020-04-08 16:46 UTC] daverandom@php.net
|
|||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Mon Nov 03 19:00:02 2025 UTC |
Description: ------------ Currently Closures can not be obtained from trace and thus it is very hard to debug which closure was used/called. This is a feature request to store the Closures in backtrace instead of strings, or for BC, provide a way how to obtain them from any trace with Closures. Test script: --------------- <?php function dump_closure_details(callable $fx) { $r = new \ReflectionFunction($fx); var_dump($r->getFileName() . ':' . $r->getStartLine()); } class Test { public function ex() { $fx = function() { return new \Exception(); }; dump_closure_details($fx); return $fx(); } public function trace() { $fx = function() { return debug_backtrace(); }; dump_closure_details($fx); return $fx(); } } $ex = (new Test())->ex(); var_dump($ex->getTrace()[0]['function']); // res['function'] is string... // dump_closure_details($ex->getTrace()[0]['function']); $trace = (new Test())->trace(); var_dump($trace[0]['function']); // res['function'] is string... // dump_closure_details($trace[0]['function']); // how to get the original closure from the exception trace or backtrace? Expected result: ---------------- Closure can be obtained from trace and can be called or passed to ReflectionFunction. Actual result: -------------- Closure is not presented in trace and there is only "{Closure}" string.