note 73656 deleted from features.commandline by danbrown
| From: | danbrown@php.net | Date: | Tue, 25 Nov 2008 15:45:18 +0000 |
| Subject: | note 73656 deleted from features.commandline by danbrown | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-146917@lists.php.net to get a copy of this message | ||
Note Submitter: jsa1971 at gmail dot com
----
python coders might miss this construct when working in PHP:
if __name__=='__main__':
# handle direct invocation from command line
it's a great way to embed little bits of test code (or a full-on cli for that matter),
while keeping the source file usable in other contexts.
Far as I can tell, this is the closest approximation available in PHP5:
if ('cli'===php_sapi_name() &&
__FILE__===realpath(
getcwd().DIRECTORY_SEPARATOR.$_SERVER['argv'][0]
)) {
// handle direct invocation from command line
}