Bug #66237 [Opn->Nab]: Mutating __toString causes array_intersect to return empty
| From: | aharvey@php.net | Date: | Wed, 11 Dec 2013 20:55:33 +0000 |
| Subject: | Bug #66237 [Opn->Nab]: Mutating __toString causes array_intersect to return empty | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-183240@lists.php.net to get a copy of this message | ||
Edit report at https://bugs.php.net/bug.php?id=66237&edit=1
ID: 66237
Updated by: aharvey@php.net
Reported by: simon at simon dot geek dot nz
Summary: Mutating __toString causes array_intersect to return
empty
-Status: Open
+Status: Not a bug
Type: Bug
Package: Unknown/Other Function
PHP Version: 5.5Git-2013-12-04 (Git)
Block user comment: N
Private report: N
New Comment:
Thank you for taking the time to write to us, but this is not
a bug. Please double-check the documentation available at
http://www.php.net/manual/ and the instructions on how to
report
a bug at http://bugs.php.net/how-to-report.php
array_intersect() is documented as comparing the string form of each element â if
that's unstable, then bad things may happen.
Previous Comments:
------------------------------------------------------------------------
[2013-12-04 21:53:53] simon at simon dot geek dot nz
Description:
------------
Hopefully the test script is self-explanatory. When running array_intersect on arrays that contains
an object that mutates itself and the return value in its __toString() method, the result is an
empty array even if there are literal values in the arrays that intersect.
Test script:
---------------
<?php
class A {
protected $i = 0;
public function __toString() {
$this->i++;
return "$this->i";
}
}
$a = new A;
$b = ['100', $a];
var_dump(array_intersect($b, $b));
Expected result:
----------------
array(1) {
[0]=>
string(3) "100"
}
Actual result:
--------------
array(0) {
}
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=66237&edit=1