Req #80517 [NEW]: Retain parent method name of Closure in call stack
From: ttijhof at wikimedia dot org
Operating system: Debian stable
PHP version: Irrelevant
Package: Scripting Engine problem
Bug Type: Feature/Change Request
Bug description:Retain parent method name of Closure in call stack
Description:
------------
When an anonymous function is encountered on the stack, it is currently
not feasible (afaik) to obtain the name of the class/method or function
where the closure was declared.
My use case is a sampling profiler observing EG(current_execute_data),
in which I'd like to report something more useful and stable to the
end-user than file path and line number.
This information would be useful to expose via debug_backtrace() as
well, although maybe that should could be a separate ticket.
Downstream code: https://github.com/wikimedia/php-excimer/
Downstream task: https://phabricator.wikimedia.org/T231335
Downstream use case: Flame graphs, such as
https://performance.wikimedia.org/php-profiling/
Test script:
---------------
class ResourceLoader {
public function getHashes() {
return array_map( function ( $module ) {
return $this->getModule( $module )->getVersionHash();
}, $moduleNames );
}
}
Expected result:
----------------
Able to construct a string like "Closure$ResourceLoader::getHashes".
Before Wikimedia upgraded to PHP 7.2, we used HHVM and its Xenon
extension, which provided "faux" function name for closures that were
unique over a given code base and added signifant value for developers
as part of stack traces.
Example:
https://github.com/facebook/hhvm/blob/HHVM-3.23.4/hphp/tools/gdb/README.md#stacktraces
https://github.com/facebook/hhvm/blob/HHVM-3.23.4/hphp/test/slow/closure/name.php.expect
Note that a method could define multiple closures, in which we could
append a number to them. HHVM did this by appending "#2" as needed.
XHProf does something similar for nested functions, by appending "@2" to
the faux function name.
Actual result:
--------------
function_name:
class_name:
filename: /tmp/foo.php
closure_line: 3
For closures, we currently format this as {closure:/tmp/foo.php(3)}
https://github.com/wikimedia/php-excimer/blob/d82eaf7b3b/excimer_log.c#L311
--
Edit bug report at https://bugs.php.net/bug.php?id=80517&edit=1
--
Fix committed: https://bugs.php.net/fix.php?id=80517&r=fixed
Fixed in release: https://bugs.php.net/fix.php?id=80517&r=alreadyfixed
Need backtrace: https://bugs.php.net/fix.php?id=80517&r=needtrace
Need Reproduce Script: https://bugs.php.net/fix.php?id=80517&r=needscript
Try newer version: https://bugs.php.net/fix.php?id=80517&r=oldversion
Not developer issue: https://bugs.php.net/fix.php?id=80517&r=support
Expected behavior: https://bugs.php.net/fix.php?id=80517&r=notwrong
Not enough info: https://bugs.php.net/fix.php?id=80517&r=notenoughinfo
Submitted twice: https://bugs.php.net/fix.php?id=80517&r=submittedtwice
register_globals: https://bugs.php.net/fix.php?id=80517&r=globals
PHP version support discontinued: https://bugs.php.net/fix.php?id=80517&r=phptooold
Daylight Savings: https://bugs.php.net/fix.php?id=80517&r=dst
IIS Stability: https://bugs.php.net/fix.php?id=80517&r=isapi
Install GNU Sed: https://bugs.php.net/fix.php?id=80517&r=gnused
Floating point limitations: https://bugs.php.net/fix.php?id=80517&r=float
No Zend Extensions: https://bugs.php.net/fix.php?id=80517&r=nozend
MySQL Configuration Error: https://bugs.php.net/fix.php?id=80517&r=mysqlcfg
Thread (5 messages)
- ttijhof at wikimedia dot org