Bug #66237 [NEW]: Mutating __toString causes array_intersect to return empty

From: Date: Wed, 04 Dec 2013 21:53:54 +0000
Subject: Bug #66237 [NEW]: Mutating __toString causes array_intersect to return empty
Groups: php.bugs 
Request: Send a blank email to php-bugs+get-183123@lists.php.net to get a copy of this message
From: simon at simon dot geek dot nz Operating system: PHP version: 5.5Git-2013-12-04 (Git) Package: Unknown/Other Function Bug Type: Bug Bug description:Mutating __toString causes array_intersect to return empty 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 bug report at https://bugs.php.net/bug.php?id=66237&edit=1 -- Try a snapshot (PHP 5.4): https://bugs.php.net/fix.php?id=66237&r=trysnapshot54 Try a snapshot (PHP 5.5): https://bugs.php.net/fix.php?id=66237&r=trysnapshot55 Try a snapshot (trunk): https://bugs.php.net/fix.php?id=66237&r=trysnapshottrunk Fixed in SVN: https://bugs.php.net/fix.php?id=66237&r=fixed Fixed in release: https://bugs.php.net/fix.php?id=66237&r=alreadyfixed Need backtrace: https://bugs.php.net/fix.php?id=66237&r=needtrace Need Reproduce Script: https://bugs.php.net/fix.php?id=66237&r=needscript Try newer version: https://bugs.php.net/fix.php?id=66237&r=oldversion Not developer issue: https://bugs.php.net/fix.php?id=66237&r=support Expected behavior: https://bugs.php.net/fix.php?id=66237&r=notwrong Not enough info: https://bugs.php.net/fix.php?id=66237&r=notenoughinfo Submitted twice: https://bugs.php.net/fix.php?id=66237&r=submittedtwice register_globals: https://bugs.php.net/fix.php?id=66237&r=globals PHP 4 support discontinued: https://bugs.php.net/fix.php?id=66237&r=php4 Daylight Savings: https://bugs.php.net/fix.php?id=66237&r=dst IIS Stability: https://bugs.php.net/fix.php?id=66237&r=isapi Install GNU Sed: https://bugs.php.net/fix.php?id=66237&r=gnused Floating point limitations: https://bugs.php.net/fix.php?id=66237&r=float No Zend Extensions: https://bugs.php.net/fix.php?id=66237&r=nozend MySQL Configuration Error: https://bugs.php.net/fix.php?id=66237&r=mysqlcfg

« previous php.bugs (#183123) next »