From: sebastian Operating system: Irrelevant PHP version: 5.4Git-2012-04-02 (Git) Package: Reflection related Bug Type: Feature/Change Request Bug description:Allow access to name of constant used as default value
Description: ------------ When a constant is used for the default value of an optional parameter, the Reflection API (tries to) resolve(s) the constant to its value and then returns it as the default value. In addition, I would like to have two additional methods in ReflectionParameter that expose 1) whether or not a default value "is a" constant and 2) the name of the constant. In the example below, I am using temporary names ("defaultValueIsConstant" and "getDefaultValueConstantName") for these two methods because I cannot think of sensible method names right now. Test script: --------------- <?php class Foo { const bar = '...'; public function baz($bar = self::bar) { } } $m = new ReflectionMethod('Foo', 'baz'); $p = $m->getParameters(); foreach ($p as $_p) { var_dump($_p->getDefaultValue()); if ($_p->defaultValueIsConstant()) { var_dump($_p->getDefaultValueConstantName()); } } Expected result: ---------------- string(3) "..." string(9) "self::bar" Actual result: -------------- string(3) "..." -- Edit bug report at https://bugs.php.net/bug.php?id=61602&edit=1 -- Try a snapshot (PHP 5.4): https://bugs.php.net/fix.php?id=61602&r=trysnapshot54 Try a snapshot (PHP 5.3): https://bugs.php.net/fix.php?id=61602&r=trysnapshot53 Try a snapshot (trunk): https://bugs.php.net/fix.php?id=61602&r=trysnapshottrunk Fixed in SVN: https://bugs.php.net/fix.php?id=61602&r=fixed Fixed in SVN and need be documented: https://bugs.php.net/fix.php?id=61602&r=needdocs Fixed in release: https://bugs.php.net/fix.php?id=61602&r=alreadyfixed Need backtrace: https://bugs.php.net/fix.php?id=61602&r=needtrace Need Reproduce Script: https://bugs.php.net/fix.php?id=61602&r=needscript Try newer version: https://bugs.php.net/fix.php?id=61602&r=oldversion Not developer issue: https://bugs.php.net/fix.php?id=61602&r=support Expected behavior: https://bugs.php.net/fix.php?id=61602&r=notwrong Not enough info: https://bugs.php.net/fix.php?id=61602&r=notenoughinfo Submitted twice: https://bugs.php.net/fix.php?id=61602&r=submittedtwice register_globals: https://bugs.php.net/fix.php?id=61602&r=globals PHP 4 support discontinued: https://bugs.php.net/fix.php?id=61602&r=php4 Daylight Savings: https://bugs.php.net/fix.php?id=61602&r=dst IIS Stability: https://bugs.php.net/fix.php?id=61602&r=isapi Install GNU Sed: https://bugs.php.net/fix.php?id=61602&r=gnused Floating point limitations: https://bugs.php.net/fix.php?id=61602&r=float No Zend Extensions: https://bugs.php.net/fix.php?id=61602&r=nozend MySQL Configuration Error: https://bugs.php.net/fix.php?id=61602&r=mysqlcfg