Process truncation using the file-like method. how can this problem be solved quickly? There are only three methods I have come up. use fopenwhile (feof) to get the content of the {} quantity truncation method body. 2. use explode (function, fopen) 3. recursion and 1. there is almost no difference. I would like to ask what method is faster? For example, PHPcode & lt ;? Phpclassa {publicfu file method process interception. which method is faster?
Methods I have come up
Only 3 types
1. use fopen while (feof) to get the {} quantity of method body content.
2. use explode ('function', fopen)
3. recursion is similar to 1.
I would like to ask what method is faster?
For example
PHP code
In this example, the content of the method body may be relatively simple and complicated.
Is there any way to get the content process of the method body more easily ??
Thank you first.
------ Solution --------------------
Get_class_methods ($ cls );
------ Solution --------------------
Reflection combined with array truncation
PHP code
Class a {public function a () {echo a;}/* B */public function B () {echo B;} // c public function c () {echo c ;}$ class = new ReflectionClass ('A'); $ method = $ class-> getMethod ('B '); $ filename = $ method-> getFileName (); // get the file name $ start = $ method-> getStartLine (); // Obtain the start row of the method $ length = $ method-> getEndLine ()-$ start; // Obtain the length of the method body $ source = file ($ filename ); $ code = implode ('', array_slice ($ source, $ start-1, $ length + 1); echo $ code;/* public function B () {echo B ;}*/