试图理解php中的getModifiers()

时间:2013-04-22 02:32:42

标签: php

<?php
class Testing
{
    final public static function foo()
    {
        return;
    }
    public function bar()
    {
        return;
    }
}

$foo = new ReflectionMethod('Testing', 'foo');

echo "Modifiers for method foo():\n";
echo $foo->getModifiers() . "\n";
echo implode(' ', Reflection::getModifierNames($foo->getModifiers())) . "\n";

$bar = new ReflectionMethod('Testing', 'bar');

echo "Modifiers for method bar():\n";
echo $bar->getModifiers() . "\n";
echo implode(' ', Reflection::getModifierNames($bar->getModifiers()));
?>

以上代码摘自php手册中的示例#1 ReflectionMethod::getModifiers()示例:http://php.net/manual/en/reflectionmethod.getmodifiers.php

问题: 代码:$foo->getModifiers(),输出是261,这是什么意思?

1 个答案:

答案 0 :(得分:1)

它是一个位域,由these constants的按位OR组成。

Reflection::getModifierNames让它更容易理解:

php> =Reflection::getModifierNames(261)
array(
  0 => "final",
  1 => "public",
  2 => "static",
)