php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #64655 array_diff_uassoc bug.
Submitted: 2013-04-17 09:57 UTC Modified: 2013-10-15 11:54 UTC
From: jeoe12 at gmail dot com Assigned:
Status: No Feedback Package: PHP options/info functions
PHP Version: 5.3Git-2013-04-17 (snap) OS: Ubuntu
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: jeoe12 at gmail dot com
New email:
PHP Version: OS:

 

 [2013-04-17 09:57 UTC] jeoe12 at gmail dot com
Description:
------------
array_diff_uassoc bug..

this function is diff args[0] to args[n-1]   
* args[n] == "user function" 



if (args[0].value == args[n-1].value) 
   ==> run to "user function" 

but..

PHP Version 5.3.5-1ubuntu7.7 

not run...






Test script:
---------------
function key_compare_func($key1, $key2)
{
    echo $key1. " ". $key2 . "<br>";

    if ($key1 == $key2)
        return 0;
    else if ($key1 > $key2)
        return 1;
    else
        return -1;
}

$array1 = array('1-1' => 1, '1-2' => 2, '1-3' => 3, '1-4' => 4);
$array2 = array('2-1' => 5, '2-2' => 6, '2-3' => 7, '2-4' => 8);

var_dump(array_diff_uassoc2($array1, $array2, 'key_compare_func'));


Expected result:
----------------
function php_compat_array_diff_uassoc()

{

    $args = func_get_args();
    if (count($args) < 3) {
        user_error('Wrong parameter count for array_diff_uassoc()', E_USER_WARNING);
        return;
    }
    $compare_func = array_pop($args);
    if (!is_callable($compare_func)) {
        if (is_array($compare_func)) {
            $compare_func = $compare_func[0] . '::' . $compare_func[1];
        }
        user_error('array_diff_uassoc() Not a valid callback ' .


            $compare_func, E_USER_WARNING);

        return;

    }

    $array_count = count($args);
    for ($i = 0; $i !== $array_count; $i++) {
        if (!is_array($args[$i])) {
            user_error('array_diff_uassoc() Argument #' .
                ($i + 1) . ' is not an array', E_USER_WARNING);
            return;
        }
    }
    $result = array();
    foreach ($args[0] as $k => $v) {
        for ($i = 1; $i < $array_count; $i++) {
            foreach ($args[$i] as $kk => $vv) {
                if ($v == $vv) {
                    $compare = call_user_func_array($compare_func, array($k, $kk));
                    if ($compare == 0) {
                        continue 3;
                    }
                }
            }

        }

        $result[$k] = $v;
    }
    return $result;
}


Patches

array_diff_uassoc_jeoe12 (last revision 2013-04-17 09:58 UTC by jeoe12 at gmail dot com)

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2013-04-17 14:01 UTC] laruence@php.net
-Status: Open +Status: Feedback
 [2013-04-17 14:01 UTC] laruence@php.net
actually, I can not understand what the bug you are talking about.....

could you please give us a simple test script, and also the expect result
 [2013-10-15 11:54 UTC] php-bugs at lists dot php dot net
No feedback was provided. The bug is being suspended because
we assume that you are no longer experiencing the problem.
If this is not the case and you are able to provide the
information that was requested earlier, please do so and
change the status of the bug back to "Re-Opened". Thank you.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Tue Dec 10 09:01:27 2024 UTC