PHPマニュアル/PEARマニュアル | ユーザフォーラムで議論/質問 | マニュアル検索 | ハイライト | ハイライトオフ | ポータル | php spot

ReflectionMethod::__construct - ReflectionMethod を作成する | JavaScript入門&応用&リファレンスなら「JavaScriptist」

  

ReflectionMethod::__construct

(PHP 5, PHP 7)

ReflectionMethod::__constructReflectionMethod を作成する

説明

public ReflectionMethod::__construct ( mixed $class , string $name )
public ReflectionMethod::__construct ( string $class_method )

新しい ReflectionMethod を作成します。

パラメータ

class

メソッドを含むクラスの名前あるいはオブジェクト (クラスのインスタンス)。

name

メソッドの名前。

class_method

クラス名とメソッド名を :: で区切ったもの。

返り値

値を返しません。

エラー / 例外

指定したメソッドが存在しない場合に ReflectionException が発生します。

例1 ReflectionMethod::__construct() の例

<?php
class Counter
{
    private static 
$c 0;

    
/**
     * カウンタをインクリメントする
     *
     * @final
     * @static
     * @access  public
     * @return  int
     */
    
final public static function increment()
    {
        return ++
self::$c;
    }
}

// ReflectionMethod のインスタンスを作成します
$method = new ReflectionMethod('Counter''increment');

// 基本情報を表示します
printf(
    
"===> The %s%s%s%s%s%s%s method '%s' (which is %s)\n" .
    
"     declared in %s\n" .
    
"     lines %d to %d\n" .
    
"     having the modifiers %d[%s]\n",
        
$method->isInternal() ? 'internal' 'user-defined',
        
$method->isAbstract() ? ' abstract' '',
        
$method->isFinal() ? ' final' '',
        
$method->isPublic() ? ' public' '',
        
$method->isPrivate() ? ' private' '',
        
$method->isProtected() ? ' protected' '',
        
$method->isStatic() ? ' static' '',
        
$method->getName(),
        
$method->isConstructor() ? 'the constructor' 'a regular method',
        
$method->getFileName(),
        
$method->getStartLine(),
        
$method->getEndline(),
        
$method->getModifiers(),
        
implode(' 'Reflection::getModifierNames($method->getModifiers()))
);

// ドキュメントコメントを表示します
printf("---> Documentation:\n %s\n"var_export($method->getDocComment(), 1));

// static 変数があれば表示します
if ($statics$method->getStaticVariables()) {
    
printf("---> Static variables: %s\n"var_export($statics1));
}

// メソッドを実行します
printf("---> Invocation results in: ");
var_dump($method->invoke(NULL));
?>

上の例の出力は、 たとえば以下のようになります。

===> The user-defined final public static method 'increment' (which is a regular method)
     declared in /Users/philip/cvs/phpdoc/test.php
     lines 14 to 17
     having the modifiers 261[final public static]
---> Documentation:
 '/**
     * カウンタをインクリメントする
     *
     * @final
     * @static
     * @access  public
     * @return  int
     */'
---> Invocation results in: int(1)

参考


忘却曲線を使ってこの知識を確実に記憶に残す

フォーラムで「ReflectionMethod::__construct - ReflectionMethod を作成する」について話す
各種マニュアル: PHPマニュアル | PEARマニュアル | Smarty(英語)マニュアル | PHP-GTKマニュアル | ReflectionMethod::__construct - ReflectionMethod を作成する」をGoogle検索
copyright © 1997-2024 PHP ドキュメント作成グループ(ライセンス). provided by php spot. マニュアル: