Elektrine lite

← Feed

@edorian@phpc.social

2026-09-11 11:43 UTC

Today someone asked how to do Python "execute if primary file" approach in PHP. if __name__ == "__main__": main() The first two ideas: if (get_included_files()[0] === __FILE__) { main(); } Which seems the most natural/stable. Other ideas: if (realpath($_SERVER['SCRIPT_FILENAME']) === __FILE__) { main(); } & if (realpath($argv[0]) === __FILE__) { main(); } For /some/ reason, nobody seemed to like my suggestion of if (!debug_backtrace()) { main(); } #php #fun

Replies (0)

No replies.