Edit report at https://bugs.php.net/bug.php?id=61602&edit=1

 ID:                 61602
 Comment by:         reeze dot xia at gmail dot com
 Reported by:        sebast...@php.net
 Summary:            Allow access to name of constant used as default
                     value
 Status:             Open
 Type:               Feature/Change Request
 Package:            Reflection related
 Operating System:   Irrelevant
 PHP Version:        5.4Git-2012-04-02 (Git)
 Block user comment: N
 Private report:     N

 New Comment:

PS:

@pierrick pull request is here https://github.com/php/php-src/pull/35.

thanks.


Previous Comments:
------------------------------------------------------------------------
[2012-04-03 05:56:12] reeze dot xia at gmail dot com

Hi, pierrick & sebastian:
   I have create another patch for this request. it differ's in:

   - rename defaultValueIsConstant to isDefaultValueConstant to match bool 
return values's is* method naming.
   - handle global constant.
   - refactor code to remove duplicate.
   - add 3 tests for it.

and I've make test everything looks fine.

please review it for me.

Thanks.

------------------------------------------------------------------------
[2012-04-03 00:24:13] pierr...@php.net

Just created a quick patch. If it's Ok with everybody I'll commit it to master 
with tests.

------------------------------------------------------------------------
[2012-04-03 00:23:24] pierr...@php.net

The following patch has been added/updated:

Patch Name: getDefaultValueConstantName.diff
Revision:   1333412604
URL:        
https://bugs.php.net/patch-display.php?bug=61602&patch=getDefaultValueConstantName.diff&revision=1333412604

------------------------------------------------------------------------
[2012-04-02 14:34:44] der...@php.net

It's definitely possible, I've just added something like this to VLD: 
https://github.com/derickr/vld/commit/f22862bfa8620780906f0e692f929a543264b5f8

------------------------------------------------------------------------
[2012-04-02 14:14:16] sebast...@php.net

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 this bug report at https://bugs.php.net/bug.php?id=61602&edit=1

Reply via email to