开发者

Get Token's Name with Reflection API

I want to find the token's name passed by augment into a function.

class Norm
{
    const 开发者_如何学PythonSTR_NORM = 0;
    const INT_NORM = 0;
}

function foo($Arg1, $Arg2 = NULL)
{
    getConstName($Arg1); # Should Return STR_NORM;
    return $Arg1, $Arg2;
}

echo foo(Norm::STR_NORM);

Is there any way to implement getConstName via the PHP Reflection API?


No, because inside foo(), the value of $Arg is just the integer 0. It has no way of knowing that this value came from a const.

For example, what should be output by the following example?

class Norm
{
    const STR_NORM = 0;
    const INT_NORM = 2;
}

echo foo( Norm::STR_NORM+2 );
echo foo( Norm::INT_NORM );

Should both of these echoes output INT_NORM?

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜