Edit report at https://bugs.php.net/bug.php?id=60198&edit=1

 ID:                 60198
 Comment by:         chx1975 at gmail dot com
 Reported by:        simon at simon dot geek dot nz
 Summary:            Array to string notice from array functions
 Status:             Open
 Type:               Bug
 Package:            *General Issues
 PHP Version:        5.4SVN-2011-11-02 (SVN)
 Block user comment: N
 Private report:     N

 New Comment:

This affects the Drupal project. All our tests are failing because of this bug. 
We see it with array_intersect_assoc().


Previous Comments:
------------------------------------------------------------------------
[2011-11-02 08:33:27] simon at simon dot geek dot nz

Description:
------------
Some of the array_* functions that compare elements in multiple arrays do so by 
(string)$elem1 === (string)$elem2.

If $elem1 or $elem2 is an array, then the array to string notice is thrown.

Two examples of functions that can throw this are array_intersect() and 
array_diff().

If these functions are not expected to take arrays with other arrays as values, 
this should be mentioned on the documentation pages.

Test script:
---------------
<?php
$left = array('b', array('a'));
$right = array('a', 'd');
print_r(array_intersect($left, $right));
print_r(array_diff($left, $right));


Expected result:
----------------
Array
(
)
Array
(
    [0] => b
    [1] => Array
        (
            [0] => a
        )

)


Actual result:
--------------
PHP Notice:  Array to string conversion in /Users/simon/test.php on line 4
PHP Notice:  Array to string conversion in /Users/simon/test.php on line 4
PHP Notice:  Array to string conversion in /Users/simon/test.php on line 5
PHP Notice:  Array to string conversion in /Users/simon/test.php on line 5
PHP Notice:  Array to string conversion in /Users/simon/test.php on line 5

Notice: Array to string conversion in /Users/simon/test.php on line 4

Notice: Array to string conversion in /Users/simon/test.php on line 4

Array
(
)

Notice: Array to string conversion in /Users/simon/test.php on line 5

Notice: Array to string conversion in /Users/simon/test.php on line 5

Notice: Array to string conversion in /Users/simon/test.php on line 5

Array
(
    [0] => b
    [1] => Array
        (
            [0] => a
        )

)



------------------------------------------------------------------------



-- 
Edit this bug report at https://bugs.php.net/bug.php?id=60198&edit=1

Reply via email to