File tree Expand file tree Collapse file tree 2 files changed +29
-0
lines changed
language/predefined/variables Expand file tree Collapse file tree 2 files changed +29
-0
lines changed Original file line number Diff line number Diff line change 182
182
also be found in the <varname >$_SERVER</varname > array, for example:
183
183
<varname >$_SERVER['argv']</varname >.
184
184
</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 >
185
206
</entry >
186
207
</row >
187
208
<row >
Original file line number Diff line number Diff line change 25
25
is disabled.
26
26
</simpara >
27
27
</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 >
28
36
</refsect1 >
29
37
30
38
<refsect1 role =" examples" >
You can’t perform that action at this time.
0 commit comments