note 63393 deleted from function.defined by bjori
| From: | bjori@php.net | Date: | Thu, 23 Mar 2006 15:16:48 +0000 |
| Subject: | note 63393 deleted from function.defined by bjori | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-106479@lists.php.net to get a copy of this message | ||
Note Submitter: gerry-03 at 4warding dot com
----
Using this function it is possible to set a default value for a constant. This allows users to set
the value of constants used in your script, from within their own. Which means your script remains
in it's original state.
yourScript.php:
<?php
if(!defined('CONST_VAL'))
define('CONST_VAL', 'Default Value');
echo CONST_VAL;
?>
userScript.php:
<?php
define('CONST_VAL', 'Hello World!');
include 'yourScript.php';
?>
If you tried just defining the constant again without using the !defined() check, you would receive
a "Constant CONST_VAL already defined" notice.