| 
        php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login | 
  [2012-06-14 17:25 UTC] anfurny22 at gmail dot com
 Description:
------------
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:
---------------
<?PHP
$anon = function() {
 $name = (debug_backtrace[0]['name']); // yields {closure}
 $refl = new ReflectionFunction($name); // works great except with closures!
 echo $refl->getDocComment(); // fails
}
$anon();
PatchesImproved_Debug_Backtrace_for_anonymous_functions (last revision 2012-06-17 10:56 UTC by anfurny22 at gmail dot com)Pull RequestsHistoryAllCommentsChangesGit/SVN commits             
             | 
    |||||||||||||||||||||||||||||||||||||
            
                 
                Copyright © 2001-2025 The PHP GroupAll rights reserved.  | 
        Last updated: Tue Nov 04 02:00:01 2025 UTC | 
This needs to be fixes by at least providing a location where Closure was defined - filename + line. Test code: $fx = (function() { print_r(debug_backtrace()); }); (function() use($fx) { $fx(); })(); -> currently there is no way to identify/trace the location of the called Closure. I see there is already patch for it here. Can someone take a look at it? If saving the Closure object is not desired, the location needs to be always accessible in order to be trace the actual trace output.