Re: Re: cvs: php-src(PHP_5_2) / NEWS configure.in /main php_version.h

From: Date: Thu, 26 Feb 2009 19:43:52 +0000
Subject: Re: Re: cvs: php-src(PHP_5_2) / NEWS configure.in /main php_version.h
References: 1 2 3 4 5 6 7 8 9 10  Groups: php.internals 
Request: Send a blank email to internals+get-43190@lists.php.net to get a copy of this message
On Fri, Feb 27, 2009 at 3:58 AM, Moriyoshi Koizumi <mozo@mozo.jp> wrote: > 1. array_unique() has never been supposed to handle values other than > strings. That's how bug #10658 is handled. That's not what I really wanted to mean. I should have said "not supposed to handle values other than scalars". Moriyoshi > http://bugs.php.net/10658 > > See also: > > http://cvs.php.net/viewvc.cgi/phpdoc/en/reference/array/functions/array-unique.xml?revision=1.16&view=markup > > 2. the results are inconsistent between SORT_STRING and SORT_REGULAR > when the items are a mixture of different types. > > <?php > $objs = array( >    "0x10", >    16, >    true, >    "true", > ); > > var_dump(array_unique($objs, SORT_REGULAR)); > var_dump(array_unique($objs, SORT_STRING)); > > $objs = array( >    "0x10", >    true, >    16, >    "true", > ); > > var_dump(array_unique($objs, SORT_REGULAR)); > var_dump(array_unique($objs, SORT_STRING)); > ?> > > I could hardly imagine what would show up. Do you? > > array(1) { >  [0]=> >  string(4) "0x10" > } > array(4) { >  [0]=> >  string(4) "0x10" >  [1]=> >  int(16) >  [2]=> >  bool(true) >  [3]=> >  string(4) "true" > } > array(2) { >  [0]=> >  string(4) "0x10" >  [3]=> >  string(4) "true" > } > array(4) { >  [0]=> >  string(4) "0x10" >  [1]=> >  bool(true) >  [2]=> >  int(16) >  [3]=> >  string(4) "true" > } > > > 3. the result can be unreasonable even with SORT_REGULAR > > As the equality of the object is only determined by member-wise > comparison, there must be cases where the behavior is not acceptable: > > <?php > class Foo { >    public $a; >    function __construct($a) { >        $this->a = $a; >    } > }; > > > $objs = array( >    new Foo(1), new Foo("2e0"), new Foo(2), new Foo(3) > ); > > var_dump(array_unique($objs, SORT_REGULAR)); > ?> > > This yields: > > array(3) { >  [0]=> >  object(Foo)#1 (1) { >    ["a"]=> >    int(1) >  } >  [1]=> >  object(Foo)#2 (1) { >    ["a"]=> >    string(3) "2e0" >  } >  [3]=> >  object(Foo)#4 (1) { >    ["a"]=> >    int(3) >  } > } > > while the second item is semantically not expected to be equal to the third. > > > Moriyoshi > >

« previous php.internals (#43190) next »