php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #61540 array_diff has problem when in second array is entry with null value
Submitted: 2012-03-28 10:23 UTC Modified: 2012-03-29 11:30 UTC
Votes:1
Avg. Score:5.0 ± 0.0
Reproduced:1 of 1 (100.0%)
Same Version:1 (100.0%)
Same OS:1 (100.0%)
From: pfraszczak at power dot com dot pl Assigned:
Status: Not a bug Package: Arrays related
PHP Version: 5.3.10 OS: ubuntu
Private report: No CVE-ID: None
 [2012-03-28 10:23 UTC] pfraszczak at power dot com dot pl
Description:
------------
I notice that array_diff return empty array when in second array we have entry with null value. When i removed entry with test key - everything works fine.

Moreover it seems that null values in $a array don't brake array_diff

Test script:
---------------
$a = array('street'=>'','number'=>'n1');
$b = array('street'=>'b1','number'=>'n1','test'=>null);
var_dump(array_diff($a,$b));


Expected result:
----------------
array(1) {
  ["street"]=>
  string(0) ""
}

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


Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2012-03-28 10:27 UTC] pfraszczak at power dot com dot pl
-Package: Scripting Engine problem +Package: Arrays related
 [2012-03-28 10:27 UTC] pfraszczak at power dot com dot pl
Changed package
 [2012-03-29 04:24 UTC] reeze dot xia at gmail dot com
Hi pfraszczak:
    This is NOT a bug. 
    because "" == NULL  => TRUE. 

if we change the test script to :

$a = array('street'=>'not-null-equal-value','number'=>'n1');
$b = array('street'=>'b1','number'=>'n1','test'=>null);
var_dump(array_diff($a,$b));

you will get the right result.
 [2012-03-29 11:30 UTC] johannes@php.net
-Status: Open +Status: Not a bug
 [2012-03-29 11:30 UTC] johannes@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.


 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Thu Apr 25 14:01:31 2024 UTC