1

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.

2
  • 2
    for future reference: this kind of capability is called Reflection. Knowing the right terms helps google help you :) Commented Sep 8, 2010 at 17:52
  • 1
    Why not simply use PHPDocumentor tags? Commented Sep 8, 2010 at 17:53

2 Answers 2

4

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

Sign up to request clarification or add additional context in comments.

Comments

2
<?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";
    }
 }
}

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.