Bug #79460 [NEW]: Backtrace does not allow to obtain/identifiy Closures

From: Date: Wed, 08 Apr 2020 16:06:32 +0000
Subject: Bug #79460 [NEW]: Backtrace does not allow to obtain/identifiy Closures
Groups: php.bugs 
Request: Send a blank email to php-bugs+get-226494@lists.php.net to get a copy of this message
From: michael dot vorisek at email dot cz Operating system: PHP version: 7.4.4 Package: Scripting Engine problem Bug Type: Bug Bug description:Backtrace does not allow to obtain/identifiy Closures 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. -- Edit bug report at https://bugs.php.net/bug.php?id=79460&edit=1 -- Fix committed: https://bugs.php.net/fix.php?id=79460&r=fixed Fixed in release: https://bugs.php.net/fix.php?id=79460&r=alreadyfixed Need backtrace: https://bugs.php.net/fix.php?id=79460&r=needtrace Need Reproduce Script: https://bugs.php.net/fix.php?id=79460&r=needscript Try newer version: https://bugs.php.net/fix.php?id=79460&r=oldversion Not developer issue: https://bugs.php.net/fix.php?id=79460&r=support Expected behavior: https://bugs.php.net/fix.php?id=79460&r=notwrong Not enough info: https://bugs.php.net/fix.php?id=79460&r=notenoughinfo Submitted twice: https://bugs.php.net/fix.php?id=79460&r=submittedtwice register_globals: https://bugs.php.net/fix.php?id=79460&r=globals PHP version support discontinued: https://bugs.php.net/fix.php?id=79460&r=phptooold Daylight Savings: https://bugs.php.net/fix.php?id=79460&r=dst IIS Stability: https://bugs.php.net/fix.php?id=79460&r=isapi Install GNU Sed: https://bugs.php.net/fix.php?id=79460&r=gnused Floating point limitations: https://bugs.php.net/fix.php?id=79460&r=float No Zend Extensions: https://bugs.php.net/fix.php?id=79460&r=nozend MySQL Configuration Error: https://bugs.php.net/fix.php?id=79460&r=mysqlcfg

« previous php.bugs (#226494) next »