PhpDig.net

What is PhpDig?
PhpDig is a PHP MySQL based
Web Spider & Search Engine.




define

Name

define — Defines a named constant.

Synopsis

bool define(name, value[, case_insensitive]);
string name: Name of the constant
mixed value: Value of the constant
integer case_insensitive (optional): Whether the constant name is case-insensitive

Returns

TRUE on success; FALSE otherwise

Description

define() is used to define named constants. Constants are similar to variables, except for the following differences:

  • Once defined, a constant's value cannot be changed.

  • Constant names do not need a leading dollar sign ($).

  • Once defined, a constant can be accessed regardless of scope. However, constants can only be accessed in a script after they have been defined.

  • Only scalar values (strings and numbers) can be represented as constants.

  • Like variables, constant names are case-sensitive. However, setting the optional case_insensitive argument to 1 makes the constant name case-insensitive.



Version

PHP Version: 3+, 4+

See also

To check whether a constant is defined:

defined()

Example

Example 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, ' &lt;', ADMIN_EMAIL, '&gt;';
?>



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.

Powered by: vBulletin Version 3.0.7
Copyright ©2000 - 2005, Jelsoft Enterprises Ltd.
Copyright © 2001 - 2005, ThinkDing LLC. All Rights Reserved.