Get class information from file
In Java you can send MyClass.class
as a param开发者_JS百科 and use get the entire class information.
I already knows about get_object_*
, but I am looking for something more advanced.
PHP does not have class literals, so you are probably looking for the Reflection API then
PHP 5 comes with a complete reflection API that adds the ability to reverse-engineer classes, interfaces, functions, methods and extensions. Additionally, the reflection API offers ways to retrieve doc comments for functions, classes and methods.
Example (demo):
Reflection::export(new ReflectionClass('DateTime'));
There is also some functions that can give you information about a class with
class_parents
— Return the parent classes of the given classclass_implements
— Return the interfaces which are implemented by the given class- various Classes and Object Functions
php also implements OOP-concept. you can do the following:
class MyClass {
private $foo;
pubclic function bar() {
return $this->foo;
}
}
function outer_foo($obj) {
echo($obj->bar());
}
$myobj = new MuyClass();
outer_foo($myob);
get_class — Returns the name of the class of an object http://php.net/manual/en/function.get-class.php
get_class_vars — Get the default properties of the class http://www.php.net/manual/en/function.get-class-vars.php
get_class_methods — Gets the class methods' names http://www.php.net/manual/en/function.get-class-methods.php
精彩评论