note 118030 added to class.reflectionclass
| From: | YoungOfCthulhu | Date: | Mon, 21 Sep 2015 14:20:58 +0000 |
| Subject: | note 118030 added to class.reflectionclass | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-203829@lists.php.net to get a copy of this message | ||
It is also possible to do reflection from within the class and get the methods for instance.
<?php
class test
{
private $test = "";
public function setTest($test)
{
$this->test = $test;
return $this;
}
public function getTest()
{
return $this->test;
}
public function run(){
$class = new ReflectionClass('test');
$methods = $class->getMethods();
var_dump($methods);
}
}
Called from another php file you get the proper result:
array(3) {
[0]=>
&object(ReflectionMethod)#3 (2) {
["name"]=>
string(8) "setTest"
["class"]=>
string(4) "test"
}
[1]=>
&object(ReflectionMethod)#4 (2) {
["name"]=>
string(8) "getTest"
["class"]=>
string(4) "test"
}
[2]=>
&object(ReflectionMethod)#5 (2) {
["name"]=>
string(3) "run"
["class"]=>
string(4) "test"
}
}
----
Server IP: 72.52.91.14
Probable Submitter: 80.156.94.2
----
Manual Page -- http://php.net/manual/en/class.reflectionclass.php
Edit -- https://master.php.net/note/edit/118030
Del: integrated -- https://master.php.net/note/delete/118030/integrated
Del: useless -- https://master.php.net/note/delete/118030/useless
Del: bad code -- https://master.php.net/note/delete/118030/bad+code
Del: spam -- https://master.php.net/note/delete/118030/spam
Del: non-english -- https://master.php.net/note/delete/118030/non-english
Del: in docs -- https://master.php.net/note/delete/118030/in+docs
Del: other reasons-- https://master.php.net/note/delete/118030
Reject -- https://master.php.net/note/reject/118030
Search -- https://master.php.net/manage/user-notes.php