|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
[2015-03-10 23:33 UTC] kenorb at gmail dot com
|
|||||||||||||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Tue Oct 28 07:00:01 2025 UTC |
Description: ------------ Hi. debug_backtrace() contains 'function' or 'class' and 'function' entries to help you determine where the code came from. No problem with that. Except. If the backtrace includes 'include' or 'require' (and their 'once' variants'), these are reported as 'function' in the backtrace. Again, no problem so far. Ish. If you use ReflectionFunction or ReflectionMethod to gather and report additional information about the trace, you get an error when dealing with the include/require entries. Uncaught exception 'ReflectionException' with message 'Function require_once() does not exist'. What is also interesting is that the output is slightly different for include/require. For a normal method/function, the order of the elements in the backtrace are : 'file' => 'SomeClass.php', 'line' => 121, 'function' => 'SomeMethod', 'class' => 'SomeClass', 'type' => '->', 'args' => array ( ), But for include/require, ... 'file' => 'SomeFile.php', 'line' => 4, 'args' => array ( 0 => '/incluldes/SomeClass.php', ), 'function' => 'require_once', So, some specialisation already exists in the backtrace for these non-functions. This is confirmed at https://github.com/php/php-src/blob/91a9569d8525d2893c83199ac83f973fb91e243b/Zend/zend_builtin_functions.c#L2345. If the debug_backtrace could include a marker indicating that the element in the trace is not reflected, OR, allow reflection of include/require (and if there was a way for eval also), then this could improve things a bit. Though, I think, just a documentation upgrade in ReflectionXXX and debug_xxx to indicate that code constructs are not reflected could cover this.