#50307 [Opn->Bgs]: case in_array does not recognize array var

From: Date: Thu, 26 Nov 2009 10:01:43 +0000
Subject: #50307 [Opn->Bgs]: case in_array does not recognize array var
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-145092@lists.php.net to get a copy of this message
 ID:               50307
 Updated by:       jani@php.net
 Reported By:      dsysko at gmail dot com
-Status:           Open
+Status:           Bogus
 Bug Type:         Scripting Engine problem
 Operating System: Ubuntu 9.10: 2.6.28-16 x64
 PHP Version:      5.3.1
 New Comment:

Try var_dump($arrChoices); in that function. Then figure out what magic
could bring the array in the function scope..


Previous Comments:
------------------------------------------------------------------------

[2009-11-26 08:29:32] dsysko at gmail dot com

Description:
------------
A pre-defined array passed to in_array() within switch{case(
interpreted as NULL for both flat and multi-dimensional arrays.

php config:
Configure Command =>  './configure'  '--with-openssl'
'--with-pgsql'
'--with-tidy' '--with-zlib' '--with-curl'
'--with-apxs2=/usr/sbin/apxs'
'--with-gd' '--with-png-dir=/usr' '--with-jpeg-dir=/usr'
'--with-freetype-dir=/usr' '--with-zlib-dir=/usr'


Reproduce code:
---------------
$arrChoices = array('numberfood' => array('apple','pie',5) ,
'monkeys'
=> array('frank','chimpanzee'));
function notArraysWhat ($i) {
   switch ($i) {
      case (in_array($i , $arrChoices['numberfood'])):
         echo "$i is either a number or a food.\n";
         break;
      case (in_array($i , $arrChoices['monkeys'])):
         echo "$i is a monkey, or smells like one.\n";
         break;
   }
}
notArraysWhat('pie');

Expected result:
----------------
STDOUT: pie is either a number or a food.

Actual result:
--------------
STDOUT: Warning: in_array() expects parameter 2 to be array, null given
in /export/servers/ETG/ContentCollection/cc/testing.php on line


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


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



Thread (2 messages)

« previous php.bugs (#145092) next »