note 73656 added to features.commandline
| From: | jsa1971 at gmail dot com | Date: | Tue, 06 Mar 2007 04:03:45 +0000 |
| Subject: | note 73656 added to features.commandline | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-124131@lists.php.net to get a copy of this message | ||
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
}
----
Server IP: 64.71.164.2
Probable Submitter: 71.243.156.9
----
Manual Page -- http://www.php.net/manual/en/features.commandline.php
Edit -- https://master.php.net/note/edit/73656
Del: integrated -- https://master.php.net/note/delete/73656/integrated
Del: useless -- https://master.php.net/note/delete/73656/useless
Del: bad code -- https://master.php.net/note/delete/73656/bad+code
Del: spam -- https://master.php.net/note/delete/73656/spam
Del: non-english -- https://master.php.net/note/delete/73656/non-english
Del: in docs -- https://master.php.net/note/delete/73656/in+docs
Del: other reasons-- https://master.php.net/note/delete/73656
Reject -- https://master.php.net/note/reject/73656
Search -- https://master.php.net/manage/user-notes.php