note 38826 added to function.error-reporting

From: Date: Wed, 07 Jan 2004 23:36:29 +0000
Subject: note 38826 added to function.error-reporting
Groups: php.notes 
Request: Send a blank email to php-notes+get-63117@lists.php.net to get a copy of this message
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= ..."; } ---- Manual Page -- http://www.php.net/manual/en/function.error-reporting.php Edit -- http://master.php.net/manage/user-notes.php?action=edit+38826 Delete -- http://master.php.net/manage/user-notes.php?action=delete+38826&report=yes Reject -- http://master.php.net/manage/user-notes.php?action=reject+38826&report=yes Search -- http://master.php.net/manage/user-notes.php

« previous php.notes (#63117) next »