php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Doc Bug #71800 string checks is_array enters into if and makes that string null
Submitted: 2016-03-11 12:32 UTC Modified: 2016-03-11 12:43 UTC
From: muhammadhu dot aiman at gmail dot com Assigned:
Status: Not a bug Package: Arrays related
PHP Version: 5.6Git-2016-03-11 (snap) OS: Ubuntu 15.04
Private report: No CVE-ID: None
 [2016-03-11 12:32 UTC] muhammadhu dot aiman at gmail dot com
Description:
------------
---
From manual page: http://www.php.net/function.is-array
---

although only array should become true and should enter inside the if, but strings enter into the is_array() and string is converted into null array.


Test script:
---------------
//a string is passed to the checkString

protected function checkString($str)
    if(is_array($str)) { //only arrays allowed here but string goes into if

        var_dump($str);exit; //string enters here and $str becoumes a null array

    } else {
        
        echo 'ok';

    }
}

result is array(0) { }

Expected result:
----------------
protected function checkString($str)
   if(is_array($str)) { //only arrays allowed here but string goes into if

        var_dump($str);exit; //string enters here and $str becoumes a null array
    
    } else {
        
        echo 'ok';

    }
  
}

result should be 'ok'

Actual result:
--------------
array(0) { }

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2016-03-11 12:43 UTC] requinix@php.net
-Status: Open +Status: Not a bug
 [2016-03-11 12:43 UTC] requinix@php.net
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.

Your code is passing in an array, not a string. PHP itself did not change $str.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Wed Apr 24 06:01:29 2024 UTC