开发者

Programmatically get class methods and properties?

OK first, 开发者_开发技巧given a file, say somefile.php is there a way to search that file for a Class?

Then, once you have the class, is there a way to get all the public properties and method signatures?

I am trying to create a way to document PHP classes on the fly.


http://php.net/manual/en/book.reflection.php


<?php

include("somefile.php");

if (class_exists("MyClass")) {
 $myclass = new ReflectionClass("MyClass");

 // getMethods() returns an array of ReflectionMethod objects
 $methods = $myclass->getMethods();

 foreach ($methods as $method) {
    print $method->getName() . "():\n";

    // getParameters() returns an array of ReflectionParameter objects
    $parameters = $method->getParameters();
    foreach ($parameters as $parm) {
      print " " . $parm . "\n";
    }
 }
}
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜