php CLI模式-f标志 [英] php CLI mode -f flag
问题描述
我正在阅读有关CLI模式下PHP的详细信息,我无法为自己解释什么实用程序具有-f标志.
有可能以"php name_of_script.php"
或"php -f name_of_script.php"
我猜这个选项只是一种语法糖.也可以用以下事实来解释它的存在:对于用户而言,当他看到-f文件被执行时,这一点更加明显.我无法弥补其他任何解释.有人看到它的其他用法了吗?
PHP已有很长的历史,许多设计决策在时间的迷茫中迷失了;我不确定任何人都可以告诉您 certain 为什么既有 -f
选项,又有没有任何选项就可以运行文件的能力.>
但是,它显然是为用户方便而设计的.大多数命令行用户都希望解释器解释作为单个参数提供的文件名,这是最常见的用例,因此使其最快地键入是有意义的.我的猜测是,PHP CLI从 just 和 -f
选项开始,后来通过仅提供文件名来运行文件的选项被添加,以改善人们的生活.更轻松.保留 -f
是为了向后兼容.
我可以想到一种情况,其中 -f
选项很有用:如果文件名以连字符开头,例如-.php
.
当作为单个参数提供时,将被视为选项,并且失败:
$ php -.php用法:php [options] [-f]< file>[-] [args ...]php [选项] -r< code>[-] [args ...]php [选项] [-B< begin_code>] -R< code...
但是,通过 -f
,它将起作用:
$ php -f -.php<脚本执行成功>
I was reading about specifics of PHP in CLI mode and I can't explain for myself what utility has -f flag.
It's possible execute any php script as "php name_of_script.php"
or "php -f name_of_script.php"
I guess this option is just kind of syntactic sugar. Also its existence can be perhaps explained by the fact that it's more obvious for user when he sees -f that file is executed. I can't make up any other explanations. Do someone see any other usage of it?
PHP has a very long history with a lot of the design decisions lost in the mists of time; I'm not sure anyone will be able to tell you for certain why there's both a -f
option and the ability to run a file without any options at all.
However, it certainly seems designed for user convenience; most command line users would expect an interpreter to interpret a filename provided as a single parameter, and it's the most common use-case, so making it the quickest to type makes sense. My guess would be that the PHP CLI started off with just the -f
option, and the option to run a file by providing just the filename was added later to make people's lives easier. The -f
was retained for backwards compatibility.
I can think of one case where the -f
option is useful: if the filename starts with a hyphen, for example -.php
.
When provided as a single parameter, this will be treated as an option, and fail:
$ php -.php
Usage: php [options] [-f] <file> [--] [args...]
php [options] -r <code> [--] [args...]
php [options] [-B <begin_code>] -R <code
...
However, with -f
, it'll work:
$ php -f -.php
<script executes successfully>
这篇关于php CLI模式-f标志的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!