note 52397 deleted from function.defined by didou
| From: | didou@php.net | Date: | Thu, 12 May 2005 12:34:01 +0000 |
| Subject: | note 52397 deleted from function.defined by didou | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-89315@lists.php.net to get a copy of this message | ||
Note Submitter: andreashaerter at plz_no_spam dot com
----
I had a litte problem which costed me a lot of time today. You *must* use defined() with quotes:
Right:
<?php
//Example echos "constant definded!" as it should do!
//Set error reporting
error_reporting(E_ALL);
//Define your constant
define('constant', 'Test');
if (defined('constant')) //Returns true
{
echo "constant definded!";
} else {
echo "constant not definded!";
}
?>
Wrong:
<?php
//Example echos "constant not definded!"
//Set error reporting
error_reporting(E_ALL);
//Define your constant
define('constant', 'Test');
if (defined(constant)) //Returns NOTHING, NO false, NO true and NO notice
{
echo "constant definded!";
} else {
echo "constant not definded!";
}
?>
You may think that's clear but PHP will give you NO notice or warning, even with
error_reporting(E_ALL) while parsing defined(constant) when 'constant' is defined!
PHP should warn you with a notice because it not even acts like when using $array[key] instead of
$array['key']! It won't return true, flase or a notice!. So take care of that!
Tested on PHP 4.3.6 and PHP 5.0.3 on Apache/2.0.49 (Win32).
Andreas Haerter [http://www.bitkultur.de]