I'm currently working on a task where I have to maintain / extend some existing code in PHP.
The PHP script in question is to be run in the terminal with php -f <script.php>.
Since this PHP file is to be run directly in the shell it would technically be feasible to just have the main namespace run through, but this doesn't seem to be the best practice.
Using Python as an example, the following idiom is quite commonly used:
def main():
...
if __name__ == "__main__":
main();
I was wondering if a similar convention also exists in PHP (ver. 8.1.10 or above).
I do think such idiom is quite desirable, as it tends to clean up the code a little. Perhaps it's also possible to select a function to be called when invoking the script or something?
I'm not a PHP developer, or rather haven't been for around 12-13 years. I checked whether there is a best-practice for something like this, but I couldn't find anything substantial.
Is there a best-practice approach to what I'm describing, or should I treat PHP code run in the shell exactly like a shellscript, etc.?