note 63393 added to function.defined
| From: | gerry-03 at 4warding dot com | Date: | Wed, 22 Mar 2006 00:05:28 +0000 |
| Subject: | note 63393 added to function.defined | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-106186@lists.php.net to get a copy of this message | ||
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.
----
Server IP: 66.163.161.117
Probable Submitter: 202.89.181.92
----
X-Spam-Status: No, hits=3.1 required=5.0 tests=DATE_MISSING,FROM_NO_LOWER
autolearn=no version=2.64
----
Manual Page -- http://www.php.net/manual/en/function.defined.php
Edit -- http://master.php.net/note/edit/63393
Del: integrated -- http://master.php.net/note/delete/63393/integrated
Del: useless -- http://master.php.net/note/delete/63393/useless
Del: bad code -- http://master.php.net/note/delete/63393/bad+code
Del: spam -- http://master.php.net/note/delete/63393/spam
Del: non-english -- http://master.php.net/note/delete/63393/non-english
Del: in docs -- http://master.php.net/note/delete/63393/in+docs
Del: other reasons-- http://master.php.net/note/delete/63393
Reject -- http://master.php.net/note/reject/63393
Search -- http://master.php.net/manage/user-notes.php