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
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
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

Add a Patch

Pull Requests

Add a Pull Request

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-2024 The PHP Group
All rights reserved.
Last updated: Mon Apr 29 11:01:32 2024 UTC