Inscrivez-vous ou connectez-vous pour rejoindre votre communauté professionnelle.
Since PHP5.0, PHP has included a reflection API, which lets us peer into any class or object and obtain detailed information on its properties, methods, interfaces,and constants. To use it, instantiate an object of either ReflectionClass or ReflectionObject and pass it the class or object to be X-rayed.
Here’s an example:
<?php
class abc {
public $prop;
public function __construct(){
echo 'Creating a new ' . get_class($this) . '...';
}
public function getname($name){
$this->prop = $name;
}
public function showname() {
return $this->prop;
}
}
class xyz extends abc {
public function __construct(){
parent::__construct();
}
}
$obj = new abc();
Reflection::export(new ReflectionClass($obj));
?>
Its result is:
Creating a new abc...Class [ class abc ] { @@ C:\\wamp\\www\\abc.php3-17 - Constants [0] { } - Static properties [0] { } - Static methods [0] { } - Properties [1] { Property [ public $prop ] } - Methods [3] { Method [<user, ctor="">public method __construct ] { @@ C:\\wamp\\www\\abc.php6 -8 } Method [ public method getname ] { @@ C:\\wamp\\www\\abc.php9 -11 - Parameters [1] { Parameter #0 [ $name ] } } Method [ public method showname ] { @@ C:\\wamp\\www\\abc.php13 -16 } } }
Cheers!
I couldn't get your question completely. But I am replying as per my understanding. You may see an object's structure using following fuction:
$a_obj = new a();
var_dump( $a_obj );