Home  >  Article  >  Backend Development  >  Getting Started with PHP: How to Use Define_PHP Tutorial

Getting Started with PHP: How to Use Define_PHP Tutorial

WBOY
WBOYOriginal
2016-07-13 17:29:44945browse

PHP pre-defines several constants and provides a mechanism to define them yourself at runtime. Constants and variables are basically the same. The difference is that constants must be defined using the DEFINE function. Once a constant is defined, it cannot be redefined.

Predefined constants in PHP:

__FILE__

The name of the script file currently being processed. If used in an included file, its value is the included file, not the containing file name.

__LINE__

The current line number of the file being processed.

PHP_VERSION

indicates the current version of the PHP processor, such as: 3.0.8-dev.

PHP_OS

The name of the operating system where the PHP processor is located, such as: Linux.

TRUE

True value

FALSE

False value

You can use the DEFINE function to define more constants.

For example, define constants:

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

Examples using __FILE__ and __LINE__

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

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/531668.htmlTechArticlePHP pre-defines several constants and provides a mechanism to define them yourself at runtime. Constants and variables are basically the same, the difference is: constants must be defined using the DEFINE function, constants...
Statement:
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