Skip to content

Commit

Permalink
Add warnings to use php_sapi_name() to test when running as CLI
Browse files Browse the repository at this point in the history
  • Loading branch information
jimwins committed Dec 22, 2024
1 parent 42bb18b commit 2c995e5
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 0 deletions.
10 changes: 10 additions & 0 deletions features/commandline.xml
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,16 @@
also be found in the <varname>$_SERVER</varname> array, for example:
<varname>$_SERVER['argv']</varname>.
</para>
<warning>
<simpara>
If a PHP script can be run via the command line or through another SAPI,
<function>php_sapi_name</function> should be used to check whether the
script is being run from the command line and <varname>$argv</varname>
is safe to use, otherwise arbitrary arguments may be passed to the
script via other SAPIs depending on how
<link linkend="ini.register-argc-argv">register_argc_argv</link> is set.
</simpara>
</warning>
</entry>
</row>
<row>
Expand Down
8 changes: 8 additions & 0 deletions language/predefined/variables/argv.xml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,14 @@
is disabled.
</simpara>
</note>
<warning>
<simpara>
To test if a script is being run from the command
line, <function>php_sapi_name</function> should be used
instead of checking whether <varname>$argv</varname> or
<varname>$_SERVER['argv']</varname> is set.
</simpara>
</warning>
</refsect1>

<refsect1 role="examples">
Expand Down

0 comments on commit 2c995e5

Please sign in to comment.