Home > php教程 > php手册 > body text

PHP入门:define的使用

WBOY
Release: 2016-06-13 10:29:15
Original
1205 people have browsed it

PHP预先定义了几个常量,并提供了一种机制在运行时自己定义。常量和变量基本上是一样的,不同的是:常量必须用DEFINE函数定义,常量一旦定义好,就不能被重新定义了。

PHP中预先定义好的常量:

__FILE__

当前正在处理的脚本文件名。如果使用在一个被包含的文件中,那么它的值就是这个被包含的文件,而不是包含它的文件名。

__LINE__

正在处理的文件的当前行数。

PHP_VERSION

表示PHP处理器的当前版本,如:3.0.8-dev。

PHP_OS

PHP处理器所在的操作系统名字,如:Linux。

TRUE

真值

FALSE

假值

可以用DEFINE函数定义更多的常量。

如,定义常量:

<?php
define("CONSTANT", "Hello world.");
echo CONSTANT; // outputs "Hello world."
?>

用 __FILE__ 和 __LINE__ 的举例

<?php
function report_error($file, $line, $message) {
echo "An error occured in $file on line $line: $message.";
}
report_error(__FILE__,__LINE__, "Something went wrong!");
?>

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Recommendations
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!