note 52397 added to function.defined
| From: | andreashaerter at plz_no_spam dot com | Date: | Fri, 29 Apr 2005 13:58:24 +0000 |
| Subject: | note 52397 added to function.defined | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-88753@lists.php.net to get a copy of this message | ||
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]
----
Manual Page -- http://www.php.net/manual/en/function.defined.php
Edit -- http://master.php.net/manage/user-notes.php?action=edit+52397
Delete: added to the manual -- http://master.php.net/manage/user-notes.php?action=delete+52397&report=yes&reason=added+to+the+manual
Delete: bad code -- http://master.php.net/manage/user-notes.php?action=delete+52397&report=yes&reason=bad+code
Delete: spam -- http://master.php.net/manage/user-notes.php?action=delete+52397&report=yes&reason=spam
Delete: useless -- http://master.php.net/manage/user-notes.php?action=delete+52397&report=yes&reason=useless
Delete: other reasons -- http://master.php.net/manage/user-notes.php?action=delete+52397&report=yes
Reject -- http://master.php.net/manage/user-notes.php?action=reject+52397&report=yes
Search -- http://master.php.net/manage/user-notes.php