php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #50307 case in_array does not recognize array var
Submitted: 2009-11-26 08:29 UTC Modified: 2010-12-20 12:50 UTC
From: dsysko at gmail dot com Assigned:
Status: Not a bug Package: Scripting Engine problem
PHP Version: 5.3.1 OS: Ubuntu 9.10: 2.6.28-16 x64
Private report: No CVE-ID: None
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: dsysko at gmail dot com
New email:
PHP Version: OS:

 

 [2009-11-26 08:29 UTC] 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

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2009-11-26 10:01 UTC] jani@php.net
Try var_dump($arrChoices); in that function. Then figure out what magic could bring the array in the function scope..
 [2010-12-20 12:50 UTC] jani@php.net
-Package: Tidy +Package: Scripting Engine problem
 
PHP Copyright © 2001-2025 The PHP Group
All rights reserved.
Last updated: Sun Jul 06 20:01:35 2025 UTC