Edit report at http://bugs.php.net/bug.php?id=51657&edit=1

 ID:          51657
 Updated by:  degeb...@php.net
 Reported by: 1234ru at gmail dot com
 Summary:     switch() construction works wrong with empty arrays
-Status:      Open
+Status:      Bogus
 Type:        Bug
 Package:     Scripting Engine problem
 PHP Version: 5.2.13

 New Comment:

Sorry, but your problem does not imply a bug in PHP itself.  For a
list of more appropriate places to ask for help using PHP, please
visit http://www.php.net/support.php as this bug system is not the
appropriate forum for asking support questions.  Due to the volume
of reports we can not explain in detail here why your report is not
a bug.  The support channels will be able to provide an explanation
for you.

Thank you for your interest in PHP.

While perhaps not immediately clear, this is correct behavior.



An empty array evaluates to false and in your snippet, isset($a['a'])
evaluates to false. In other words, $a == isset($a['a']), and so the
first case in your switch will be used.


Previous Comments:
------------------------------------------------------------------------
[2010-04-25 00:11:41] 1234ru at gmail dot com

Description:
------------
When building switch() structure using arrays, if array is empty, first
case always fires (while it should not)



(version 5.2.12)

Test script:
---------------
$a = array();

switch($a) {

        case (isset($a['a']) ): echo 'If $a is empty, you should not see it';
break;

        default: echo 'Hello.'; break;

}



------------------------------------------------------------------------



-- 
Edit this bug report at http://bugs.php.net/bug.php?id=51657&edit=1

Reply via email to