Process interception of file-like methods. how can this problem be solved quickly?-php Tutorial

Source: Internet
Author: User
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 ;}*/

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.