PHP equivalent of Python's __name__ == “__main__”?

前端 未结 3 1328
独厮守ぢ
独厮守ぢ 2021-01-31 02:59

As per the title, is there PHP equivalent of __name__ == \"__main__\"?

Is there something that would work for both scripts executed through the command line

3条回答
  •  不要未来只要你来
    2021-01-31 03:10

    You probably want one of the "Magic Constants". Depending on what you are trying to do, __FILE__, __FUNCTION__ or __CLASS__ may give you the information you are after.

    They are pretty self explanatory:

    • __FILE__gives you the current file name
    • __FUNCTION__ gives you the name of the current function
    • __CLASS__ gives you the name of the current class.

    Check the manual for more details

提交回复
热议问题