0

Hi, can someone give me idea how can I get information about namespace, class and method name and all parameters names for all public methods in class that extends MyMainClass?
For example, I have script like this:

<?php
require 'MyMainClass.php';
namespace myNameSpace;
class MyClass extends MyMainClass
{
public function myFunctionOne($firstParam,$otherParam)
{} 
public function myFunctionTwo($paramName)
{}
}
class MyOtherClass extends MyMainClass
{
public function myFunction()
{} 
}
?>

I want to have as output something like this:
myNameSpace->[MyClass]->[myFunctionOne]->[params: "firstParam, otherParam"]
myNameSpace->[MyClass]->[myFunctionTwo]->[params: "paramName"]
myNameSpace->[MyOtherClass]->[myFunction]->[params: ""]

2
Contributors
4
Replies
5
Views
7 Years
Discussion Span
Last Post by LordWEB
0

Hi,

I think the closest you can get is to use the function get_class_methods(), to which you pass the class name for which you want the method. Although this doesn't provide a list of the method parameters.

// E.g. If calling from within the class for which you want all the methods
get_class_methods(__CLASS__);

R.

Edited by blocblue: n/a

0

Yes, I know for that function

get_class_methods

but I want more sophisticated solution unfortunately.

0

I figure it out that I need to use reflection to receive information I want, but I'm not sure how...

0

Does anyone read this? :)

I have this code now:

<?php
require("MyReflectionClass.php");
class MySimpleClass {//should not be catch for reflection
	public static function MyFunction()
	{}
}
class MyOtherClass extends MyReflectionClass{ //should be cached for reflection
	public static function MyFunction($firstParam,$secondParam) //should be cached for reflection
	{}
	public static function MyFunctionNoTwo() //should be cached for reflection
	{}
}
function MySimpleFunction() //should not be catch for reflection
{}
new MyReflectionClass();
?>

and this as "MyReflectionClass.php"

<?php	
class MyReflectionClass
{
	private function GetReflection()
	{		
		$reflector = new ReflectionClass("MyReflectionClass"); 
		echo "Class name: ".$reflector->getName()."<br/>";
		echo "Defined in file: ".$reflector->getFileName()."<br/>"; 		
		
		foreach (get_class_methods("MyReflectionClass") as $methodName) {
			echo "<br/>Method found: $methodName<br/>";
			$method = $reflector->getMethod($methodName);		
			$parameters = $method->getParameters();
			var_dump($parameters);			
		} 
	}	
	function __construct() {
       $this->GetReflection();
	}
}
?>

How can I get all class reflection that MyReflectionClass extends, in this case for class "MyOtherClass"

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.