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";
}
}
}
精彩评论