note 38826 deleted from function.error-reporting by nlopess
| From: | nlopess@php.net | Date: | Thu, 08 Jan 2004 16:16:10 +0000 |
| Subject: | note 38826 deleted from function.error-reporting by nlopess | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-63159@lists.php.net to get a copy of this message | ||
Note Submitter: mega-squall@caramail.com
----
For those who use a Parse-leveled error reporting (or any level that won't diplay
'notices'), you can use an undefined variable instead of a null one :
if (!!$varaible)
{ echo "Variable is set to $variable"; }
else
{ echo "Set variable to : <input type= ..."; }
THIS IS NOT THE WAY IT SHOULD BE WRITTEN, but for tiny scripts it's lighter, and easier to read
(and it's working). We should always define variables and use null value for those with no
value or a 'to be defined' value. This is quite important because such use of undefined
variables *MIGHT* not be allowed in later releases of PHP. Howerver, the advantage of undefined
varaibles is that you don't have to always be defining a huge amount of variables when you only
use a couple at once.
If you intend to use defined variables, you may reverse condition & commands, so that undefined
variables echoes a notice "$variable not defined is *.php", a null variable echoes a
"What value do you want ?" or "I need a value to work, please tell me :", and of
course defined && !null varaibles acts properly :
if (!$variable)
{ echo "Set variable to : <input type= ..."; }
else
{ echo "Variable is set to $variable"; }
Many people write such forks with isset() function (well, I know many of them who does), because
it's bypassing the Notice-leveled error reporting's output. But it's stupid, because
this level's role is to find undefined varaibles ! They just need to define varaiables or use a
Parse-leveled error reporting. Moreover it's more difficult to read than the two examples shown
above :
if (isset($variable))
{ echo "Variable is set to $variable"; }
else
{ echo "Set variable to : <input type= ..."; }