In php, how do I obtain the current file name that calls this function in the function?

Source: Internet
Author: User
It is easy to get the current FILE name in php. Use the _ FILE _ constant. But what should I do if I define a general function and obtain the file that is currently called every time it is called? {Code...} is the above effect. It is very easy to get the current file name in php by calling get... __FILE__Constant. But what should I do if I define a general function and obtain the file that is currently called every time it is called?


  

   

That is, the above effect, I callget_current_fileTo obtain the current call file, suchaction.php.

This is just an example. In actual use, I will not simply get the file name, but use some logic, but this is the most important step.

Reply content:

It is easy to get the current file name in php.__FILE__Constant. But what should I do if I define a general function and obtain the file that is currently called every time it is called?


    

     

That is, the above effect, I callget_current_fileTo obtain the current call file, suchaction.php.

This is just an example. In actual use, I will not simply get the file name, but use some logic, but this is the most important step.

Can Try http://cn2.php.net/manual/zh/function.debug-backtrace.php
There is an example similar to what you want.


      " : "";    $c .= ($func != '') ? $func . "(): " : "";    return($c);}

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.