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

前端 未结 3 1325
独厮守ぢ
独厮守ぢ 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:31

    if (!count(debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS)))
    {
        // some usefull stuff
    }
    

    look at https://www.php.net/manual/en/function.debug-backtrace.php for more details on debug_backtrace function

提交回复
热议问题