PHP 定義了一些內定(常數),使用者也可以自訂.
內定的常數有 __FILE__ and __LINE__,這兩個常數是處理相對應的 檔名及行數.
|
Example 6-1. Using __FILE__ and __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!"); ?>
|
使用者可以自訂需要的常數. define() and undefine() functions.
|
Example 6-2. Defining Constants
<?php define("CONSTANT", "Hello world.");
echo CONSTANT; // outputs "Hello world." undefine ("CONSTANT"); ?>
|