Today someone asked how to do Python "execute if primary file" approach in PHP. ...

@edorian@phpc.social

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