繁体   English   中英

试图了解php中的getModifiers()

[英]trying to understand getModifiers() in 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手册中的Example#1 ReflectionMethod::getModifiers()示例: http ReflectionMethod::getModifiers()

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

它是一个位域,由这些常量的按位或组成。

Reflection::getModifierNames使它更易于理解:

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM