首頁 >後端開發 >php教程 >PHP中常用預定義常數及實例

PHP中常用預定義常數及實例

伊谢尔伦
伊谢尔伦原創
2017-04-07 15:08:383386瀏覽

PHP中可以使用預先定義常數來取得PHP中的資訊。

PHP常用的預定義常數如下:

###Constant nameDescription##__FILE____LINE__PHP_OS PHP_VERSIONTRUEFALSENULLE_ERRORE_WARNING
The default constant is the PHP program file name
The default constant is the number of PHP program lines
Built-in constants refer to the name of the operating system that executes the PHP parser
Built-in constants refer to the version of the PHP program
The constant is a true value
The constant is a false value
A null value
Error, causing the php script to terminate
Warning will not cause the php script to terminate
E_PARSE Parse errors, reported by the program parser
E_NOTICE Non-critical errors, such as variables not initialized

Note: The "" in FILE and LINE are two underscores, not one "_".

Description: The predefined constants starting with E_ are the error debugging part of PHP.


PHP predefined constant example:

# #There is no difference in usage between predefined constants and user-defined constants. The following uses predefined constants to output information in PHP.

<?php
    echo "PHP程序当前文件路径名:".FILE;
    echo "<br >PHP程序当前行数:".LINE;
    echo "<br >当前PHP程序的版本:".PHP_VERSION;
    echo "<br >当前操作系统:".PHP_OS;
?>

Output results similar to the following:

PHP程序当前文件路径名:D:\phpStudy\www\index.php
PHP程序当前行数:3
当前PHP程序的版本:5.6.27
当前操作系统:WINNT

Note: Depending on the operating system and software version used by each user, the results may not be the same.


以上是PHP中常用預定義常數及實例的詳細內容。更多資訊請關注PHP中文網其他相關文章!

陳述:
本文內容由網友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發現涉嫌抄襲或侵權的內容,請聯絡admin@php.cn