faqts : Computers : Programming : Languages : PHP : kms

+ Search
Add Entry AlertManage Folder Edit Entry Add page to http://del.icio.us/
Did You Find This Entry Useful?

7 of 8 people (88%) answered Yes
Recently 7 of 8 people (88%) answered Yes

Entry

How to find out if I am included?

Jul 29th, 2001 07:51
Steven Haryanto,


I am looking for the equivalent of Python's:

 if __name__ == '__main__':
     # i am invoked directly
 else:
     # i am included from some other file

Currently I use:

 if (!in_array(realpath(__FILE__), get_included_files())) {
     # i am invoked directly
 } else {
     # i am included from some other file
 }

but wonder if there is a simple, faster, more elegant way (builtin 
support from PHP perhaps?)