2011/11/2 Etienne Kneuss <col...@php.net>: > Hi, > > On Wed, Nov 2, 2011 at 17:27, Stas Malyshev <smalys...@sugarcrm.com> wrote: >> Hi! >> >>> What about array_diff(array("Array"), array(array()))? To me the sole >>> act of having an array in it is an almost sure indication that the code >>> is wrong somewhere... IMO it deserves a notice. >> >> That one would have the arrays different. > > Well, they are not different elements w.r.t array_diff, so it does > return array() since (string)"Array" === (string)array(). > > My point is: there is an implicit usage of string representations in > those functions due to the cast. And it can yield various unexpected > results. > > Another example is: > > array_intersect(array(array(1)), array(array(2))) === array(array(1)). > Even though array(1) != array(2). > > To me it falls exactly within what the patch tries to achieve: report > potential unintentional misuses of arrays.
That was indeed my exact intention when doing that patch. >> Having multi-dimensonal arrays is >> not an error, comparing arrays of different structure is not an error >> either. Consider expression: "a" == array(). Is it an error? No, it's just a >> false expression. > > Right, but that's not the question here. We are not normally comparing > the elements, arrays or not, we are comparing their string > representations, which in the case of arrays makes almost no sense to > compare. Exactly. No more no less than you expect: array_diff( array( new stdClass ), array( "stdClass" ) ); to produce: PHP Catchable fatal error: Object of class stdClass could not be converted to string in ... >> In the same way all comparisons where you compare string >> to array should just say it's not equal, since we know they're not equal. > > I surely don't expect it to issue a Notice if I do $var == "asd" and > $var turns out to be an array. But then again, it's not the question > here. > >> >> -- >> Stanislav Malyshev, Software Architect >> SugarCRM: http://www.sugarcrm.com/ >> (408)454-6900 ext. 227 >> > > > > -- > Etienne Kneuss > http://www.colder.ch -- PHP Internals - PHP Runtime Development Mailing List To unsubscribe, visit: http://www.php.net/unsub.php