File tree Expand file tree Collapse file tree
language/predefined/variables Expand file tree Collapse file tree Original file line number Diff line number Diff line change 182182 also be found in the <varname >$_SERVER</varname > array, for example:
183183 <varname >$_SERVER['argv']</varname >.
184184 </para >
185+ <warning >
186+ <para >
187+ The presence of <varname >$argv</varname > or <varname >$_SERVER['argv']</varname >
188+ is not a reliable indication that a script is being run from the
189+ command line because they may be set in other contexts when
190+ <link linkend =" ini.register-argc-argv" >register_argc_argv</link > is enabled.
191+ The value returned by <function >php_sapi_name</function > should be checked
192+ instead.
193+ <informalexample >
194+ <programlisting role =" php" >
195+ <![CDATA[
196+ <?php
197+
198+ if (php_sapi_name() === 'cli') {
199+ echo "This is being run from the command line!\n";
200+ }
201+ ]]>
202+ </programlisting >
203+ </informalexample >
204+ </para >
205+ </warning >
185206 </entry >
186207 </row >
187208 <row >
Original file line number Diff line number Diff line change 2525 is disabled.
2626 </simpara >
2727 </note >
28+ <warning >
29+ <simpara >
30+ To test if a script is being run from the command
31+ line, <function >php_sapi_name</function > should be used
32+ instead of checking whether <varname >$argv</varname > or
33+ <varname >$_SERVER['argv']</varname > is set.
34+ </simpara >
35+ </warning >
2836 </refsect1 >
2937
3038 <refsect1 role =" examples" >
You can’t perform that action at this time.
0 commit comments