Req #50331 [Com]: undefined constant is consider to be string

From: Date: Wed, 28 Mar 2012 08:40:02 +0000
Subject: Req #50331 [Com]: undefined constant is consider to be string
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-168909@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=50331&edit=1 ID: 50331 Comment by: php dot net at doppy dot nl Reported by: wdolek at gmail dot com Summary: undefined constant is consider to be string Status: Open Type: Feature/Change Request Package: Scripting Engine problem Operating System: GNU/Linux PHP Version: 5.2.11 Block user comment: N Private report: N New Comment: When any unknown constant is converted to a string a NOTICE is given. You have to make sure error_reporting shows these notices. When I insert this before your code: <?php error_reporting(-1); ?> I get the following result: ---------------------------------------- PHP Notice: Use of undefined constant MY_DEFINED_CONSTANT - assumed 'MY_DEFINED_CONSTANT' in ./test.php on line 6 value of constant is TRUE ---------------------------------------- The automatic conversion of a non existing constant to a string is annoying. But making it a fatal error is probably more problematic. And off course you get a TRUE result in the expression as the string is not empty or 0. I always recommend programming with error_reporting set to *ALL* errors reported. In production you can reduce that a bit, but when programmed correctly the logfile will still be small. Previous Comments: ------------------------------------------------------------------------ [2009-11-30 10:38:45] derick@php.net I wouldn't mind kicking this out in PHP 6 either... ------------------------------------------------------------------------ [2009-11-30 10:28:09] wdolek at gmail dot com Description: ------------ when using undefined constant, PHP consider name of constant to be string. when using this constant in if () or anywhere else, string value is cast as TRUE, which could confuse developer Reproduce code: --------------- // define('MY_DEFINED_CONSTANT', FALSE); if (MY_DEFINED_CONSTANT) { echo 'value of constant is TRUE'; } else { echo 'value of constant is FALSE'; } Expected result: ---------------- * error or at least warning, that we are using undefined constant * Actual result: -------------- value of constant is TRUE ------------------------------------------------------------------------ -- Edit this bug report at https://bugs.php.net/bug.php?id=50331&edit=1

« previous php.bugs (#168909) next »