Bug #77584 [Opn]: switch case problem

From: Date: Fri, 08 Feb 2019 08:04:35 +0000
Subject: Bug #77584 [Opn]: switch case problem
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-219426@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=77584&edit=1

 ID:                 77584
 User updated by:    giolaza at gmail dot com
 Reported by:        giolaza at gmail dot com
 Summary:            switch case problem
 Status:             Open
 Type:               Bug
 Package:            *General Issues
 Operating System:   ubuntu
 PHP Version:        7.2Git-2019-02-08 (Git)
 Block user comment: N
 Private report:     N

 New Comment:

forgot write comment //$var=1;


Previous Comments:
------------------------------------------------------------------------
[2019-02-08 08:03:45] giolaza at gmail dot com

Description:
------------
wrong case using when I am using in_array in empty var;
if var is not empty, for example - $var=0 all works right.

Test script:
---------------
$array=['users','documents','timePunch','vacation','requests'];

$var=1;
$var='';
var_dump($var);
echo PHP_EOL;
switch($var){
	case (in_array($var,$array)):
		echo 'CASE IS TRUE';
		break;
	default:
		echo 'CASE IS DEFAULT';
		break;
}
echo PHP_EOL;
var_dump(in_array($var,$array));



Expected result:
----------------
string(0) ""

CASE IS DEFAULT
bool(false)


Actual result:
--------------
string(0) ""

CASE IS TRUE
bool(false)



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



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


Thread (5 messages)

« previous php.bugs (#219426) next »