Bug #79460 [Opn->Nab]: Backtrace does not allow to obtain/identifiy Closures

From: Date: Wed, 08 Apr 2020 16:46:09 +0000
Subject: Bug #79460 [Opn->Nab]: Backtrace does not allow to obtain/identifiy Closures
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-226495@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=79460&edit=1 ID: 79460 Updated by: daverandom@php.net Reported by: michael dot vorisek at email dot cz Summary: Backtrace does not allow to obtain/identifiy Closures -Status: Open +Status: Not a bug Type: Bug Package: Scripting Engine problem PHP Version: 7.4.4 Block user comment: N Private report: N New Comment: Please do not submit the same bug more than once. An existing bug report already describes this very problem. Even if you feel that your issue is somewhat different, the resolution is likely to be the same. Thank you for your interest in PHP. The ['function'] key of a trace is always a string, indicating the name of the called function, it is therefore not correct location in the trace for this information to appear. While I don't disagree that this would be a potentially useful and sensible thing to include in the backtrace, unfortunately I don't think it's likely to be particularly practical to include, for a number of reasons. I'm closing this as a duplicate of https://bugs.php.net/bug.php?id=62325, the issue perhaps warrants further discussion which should be conducted there. Previous Comments: ------------------------------------------------------------------------ [2020-04-08 16:06:32] michael dot vorisek at email dot cz 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 this bug report at https://bugs.php.net/bug.php?id=79460&edit=1

« previous php.bugs (#226495) next »