php-doc-en/language/constants.sgml
James Gingerich e1be327855 Whee. Now the language stuff is broken back up into a bunch of seperate
files again. (Only this time, the way it is divided up makes a bit of
sense.)


git-svn-id: https://svn.php.net/repository/phpdoc/en/trunk@9863 c90b9560-bf6c-de11-be94-00142212c4b1
1999-06-20 02:25:34 +00:00

174 lines
4 KiB
Text
Raw Blame History

<chapter id="language.constants">
<title>Constants</title>
<simpara>
PHP defines several constants and provides a mechanism for
defining more at run-time. Constants are much like variables,
save for the two facts that constants must be defined using the
<function>define</function> function, and that they cannot later be
redefined to another value.
<para>
The predefined constants (always available) are:
<variablelist>
<varlistentry>
<term>__FILE__</term>
<listitem>
<simpara>
The name of the script file presently being parsed. If used
within a file which has been included or required, then the
name of the included file is given, and not the name of the
parent file.
</simpara>
</listitem>
</varlistentry>
<varlistentry>
<term>__LINE__</term>
<listitem>
<simpara>
The number of the line within the current script file which is
being parsed. If used within a file which has been included or
required, then the position within the included file is given.
</simpara>
</listitem>
</varlistentry>
<varlistentry>
<term>PHP_VERSION</term>
<listitem>
<simpara>
The string representation of the version of the PHP parser
presently in use; e.g. '3.0.8-dev'.
</simpara>
</listitem>
</varlistentry>
<varlistentry>
<term>PHP_OS</term>
<listitem>
<simpara>
The name of the operating system on which the PHP parser is
executing; e.g. 'Linux'.
</simpara>
</listitem>
</varlistentry>
<varlistentry>
<term>TRUE</term>
<listitem>
<simpara>
A true value.
</simpara>
</listitem>
</varlistentry>
<varlistentry>
<term>FALSE</term>
<listitem>
<simpara>
A false value.
</simpara>
</listitem>
</varlistentry>
<varlistentry>
<term>E_ERROR</term>
<listitem>
<simpara>
Denotes an error other than a parsing error from which
recovery is not possible.
</simpara>
</listitem>
</varlistentry>
<varlistentry>
<term>E_WARNING</term>
<listitem>
<simpara>
Denotes a condition where PHP knows something is wrong, but
will continue anyway; these can be caught by the script
itself. An example would be an invalid regexp in
<function>ereg</function>.
</simpara>
</listitem>
</varlistentry>
<varlistentry>
<term>E_PARSE</term>
<listitem>
<simpara>
The parser choked on invalid syntax in the script
file. Recovery is not possible.
</simpara>
</listitem>
</varlistentry>
<varlistentry>
<term>E_NOTICE</term>
<listitem>
<simpara>
Something happened which may or may not be an error. Execution
continues. Examples include using an unquoted string as a
hash index, or accessing a variable which has not been set.
</simpara>
</listitem>
</varlistentry>
</variablelist>
<para>
The E_* constants are typically used with the
<function>error_reporting</function> function<6F>for setting the
error reporting level.
<para>
You can define additional constants using the
<function>define</function> function.
<para>
Note that these are constants, not C-style macros; only valid
scalar data may be represented by a constant.
<example>
<title>Defining Constants</title>
<programlisting>
&lt;?php
define("CONSTANT", "Hello world.");
echo CONSTANT; // outputs "Hello world."
?&gt;
</programlisting>
</example>
<example>
<title>Using __FILE__ and __LINE__</title>
<programlisting>
&lt;?php
function report_error($file, $line, $message) {
echo "An error occured in $file on line $line: $message.";
}
report_error(__FILE__,__LINE__, "Something went wrong!");
?&gt;
</programlisting>
</example>
</chapter>
<!-- Keep this comment at the end of the file
Local variables:
mode: sgml
sgml-omittag:t
sgml-shorttag:t
sgml-minimize-attributes:nil
sgml-always-quote-attributes:t
sgml-indent-step:1
sgml-indent-data:t
sgml-parent-document:nil
sgml-default-dtd-file:"../manual.ced"
sgml-exposed-tags:nil
sgml-local-catalogs:nil
sgml-local-ecat-files:nil
End:
-->