defineDescriptiondefine() is used to define named constants. Constants are similar to variables, except for the following differences:
ExampleExample 748. Define a constant and use it in a few different contexts <?php // Define a case-insensitive constant define ('ADMIN_NAME', 'A. Bofh', TRUE); // Define a case-sensitive constant define ('ADMIN_EMAIL', 'A.Bofh@fear-and-loathing.com'); function catch_error ($err_lvl, $err_msg) { switch ($err_lvl) { case 1: $err_type = 'Minor Bug'; break; case 2: $err_type = 'Major Bug'; break; case 3: $err_type = 'By the time you get this, the smoke alarm should be sounding.'; break; default: $err_type = "Something bad happened, but I won't tell you what it is."; break; } // The ADMIN_EMAIL constant is automatically available in the scope of this function // and, in this case, the constant name is case-sensitive. mail ( ADMIN_EMAIL, $err_type, "Error on page <i>$GLOBALS[SCRIPT_NAME]</i> - the exact message is $err_msg" ); } // ... body code goes here // Note that the constant name is not case-sensitive // This is because the optional case_insensitive parameter is set echo 'This site is maintained by ', Admin_Name, ' <', ADMIN_EMAIL, '>'; ?>
PHP Functions Essential Reference. Copyright © 2002 by New Riders Publishing
(Authors: Zak Greant, Graeme Merrall, Torben Wilson, Brett Michlitsch).
This material may be distributed only subject to the terms and conditions set forth
in the Open Publication License, v1.0 or later (the latest version is presently available at
http://www.opencontent.org/openpub/).
The authors of this book have elected not to choose any options under the OPL. This online book was obtained
from http://www.fooassociates.com/phpfer/
and is designed to provide information about the PHP programming language, focusing on PHP version 4.0.4
for the most part. The information is provided on an as-is basis, and no warranty or fitness is implied. All
persons and entities shall have neither liability nor responsibility to any person or entity with respect to
any loss or damage arising from the information contained in this book.
|