Bug #68105 [Wfx]: Switch shouldn't show notices for undefined variables
| From: | jacob87 at o2 dot pl | Date: | Fri, 26 Sep 2014 23:03:28 +0000 |
| Subject: | Bug #68105 [Wfx]: Switch shouldn't show notices for undefined variables | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-187726@lists.php.net to get a copy of this message | ||
Edit report at https://bugs.php.net/bug.php?id=68105&edit=1
ID: 68105
User updated by: jacob87 at o2 dot pl
Reported by: jacob87 at o2 dot pl
Summary: Switch shouldn't show notices for undefined
variables
Status: Wont fix
Type: Bug
Package: Output Control
PHP Version: 5.5.17
Block user comment: N
Private report: N
New Comment:
What kind of harm whould that possibly do?!
If switch has default value, it should be the same as default value for function!
Please, consider this once again.
Previous Comments:
------------------------------------------------------------------------
[2014-09-26 09:17:07] requinix@php.net
Doing so would cause much harm for very little good. The variable is undefined so don't try to
use it, period. It's a simple rule that's very easy to follow.
------------------------------------------------------------------------
[2014-09-26 08:25:45] jacob87 at o2 dot pl
Description:
------------
Switch should not show notices about undefined variables, as it can have it's default action.
So, the notice shouldn't show up if switch has default action (best implementation).
Or not show notices at all (easier).
You could say "just turn off notices in production environment". That is not the case. In
development environment some scripts can fail because of "Headers already sent". And I
don't want to write redundant code such as if(!isset($var))$var='';
Test script:
---------------
switch($action){
default:
echo 'This shouldn't show a notice!';
break;
}
Expected result:
----------------
This shouldn't show a notice!
Actual result:
--------------
Notice: Undefined variable: action in (...)
This shouldn't show a notice!
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=68105&edit=1