tags:

views:

43

answers:

2

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.

+4  A: 

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

Visage
+1 thanks that link helped too.
John Isaacks
+2  A: 
<?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";
    }
 }
}
Bill Karwin