|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Request #62325 Debug Backtrace gives no handle to anonymous functions
Submitted: 2012-06-14 17:25 UTC Modified: -
Avg. Score:4.1 ± 0.8
Reproduced:7 of 7 (100.0%)
Same Version:2 (28.6%)
Same OS:2 (28.6%)
From: anfurny22 at gmail dot com Assigned:
Status: Open Package: *General Issues
PHP Version: 5.4.4 OS: Windows
Private report: No CVE-ID: None
Have you experienced this issue?
Rate the importance of this bug to you:

 [2012-06-14 17:25 UTC] anfurny22 at gmail dot com
Debug backtrace traditionally gives several pieces of information about the call 
stack, including file name, line number, and function name. However, with 
anonymous functions it simply gives "{closure}". This makes anonymous functions 
received through debug_backtrace inaccesible through reflection because there is 
no reference to them.

I propose that debug_backtrace always provide an additional key "reference" which 
is a reference to the actual function. This will let the function be called or 
provided to the reflection API.

Test script:

$anon = function() {
 $name = (debug_backtrace[0]['name']); // yields {closure}
 $refl = new ReflectionFunction($name); // works great except with closures!
 echo $refl->getDocComment(); // fails



Improved_Debug_Backtrace_for_anonymous_functions (last revision 2012-06-17 10:56 UTC by anfurny22 at gmail dot com)

Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2012-06-17 11:01 UTC] hanskrentel at yahoo dot de
I think the naming can be improved. Reference is quite generic, why not to return 
some reflection object if asked for?
 [2012-06-17 11:22 UTC] anfurny22 at gmail dot com
I agree the key name is ambiguous, perhaps 'function_reference' instead of 

I'm unclear what you're saying about "returning" a reflection object, please 
 [2016-06-07 10:33 UTC] contact at jaborandi dot org dot ru
Because of this lack of support for closure by debug_backtrace, it is impossible to get the scope of the closure from within the closure in case when $this was changed by binding closure to something else.

This problem remains in php 7.0.7
PHP Copyright © 2001-2019 The PHP Group
All rights reserved.
Last updated: Tue Nov 19 03:01:36 2019 UTC