#21920 [Ver]: array_unique buggy example and BC

From: Date: Fri, 09 Apr 2004 02:31:41 +0000
Subject: #21920 [Ver]: array_unique buggy example and BC
References: 1  Groups: php.doc 
Request: Send a blank email to phpdoc+get-969359990@lists.php.net to get a copy of this message
ID: 21920 Updated by: progcom@php.net Reported By: corinl at gmx dot de Status: Verified Bug Type: Documentation problem PHP Version: 4.3.0 New Comment: From PHP 4.3.0, array_unique() returns the key of the first related value from the unsorted array. http://cvs.php.net/diff.php/php-src/ext/standard/array.c?r1=1.167&r2=1.168&ty=h In addition, prior to PHP 4.0.5 used REGULAR SORT, not STRING SORT, and PHP 4.0.4 also compared type (broken behavior) http://cvs.php.net/diff.php/php-src/ext/standard/array.c?r1=1.76&r2=1.77&ty=h http://cvs.php.net/diff.php/php-src/ext/standard/array.c?r1=1.86&r2=1.87&ty=h Previous Comments: ------------------------------------------------------------------------ [2003-02-05 02:23:13] philip@php.net Both examples were wrong but have been updated to reflect current (4.3.0) behavior. Am leaving this open until someone can figure out when (or if) the behavior changed. Apparently the second example was from 4.0.6 but hmm, this is odd. Nothing in NEWS reflects a change. http://cvs.php.net/cvs.php/phpdoc/en/reference/array/functions/array-unique.xml And a historical reference: http://cvs.php.net/cvs.php/phpdoc/en/functions/array.xml ------------------------------------------------------------------------ [2003-01-28 11:23:03] philip@php.net Maybe the documented example was created on a PHP 4.0.4 box ;) ------------------------------------------------------------------------ [2003-01-28 10:47:49] andrey@php.net The docs : [snip] Note that keys are preserved. array_unique() sorts the values treated as string at first, then will keep the first key encountered for every value, and ignore all following keys. It does not mean that the key of the first related value from the unsorted array will be kept. [/snip] I get the users result on Windows(4.3.0-dev), RH 6.2(4.3.0-dev), Debian 3.0 (5.0.0-dev). The docs should be changed. ------------------------------------------------------------------------ [2003-01-28 10:31:19] betz@php.net I get: php -v PHP 4.3.0 (cli) (built: Jan 8 2003 16:10:13) Copyright (c) 1997-2002 The PHP Group Zend Engine v1.3.0, Copyright (c) 1998-2002 Zend Technologies php test.php Array ( [a] => grün [0] => rot [1] => blau } Friedhelm ------------------------------------------------------------------------ [2003-01-28 10:26:38] corinl at gmx dot de okay, so as you can the *keys* are different! ------------------------------------------------------------------------ The remainder of the comments for this report are too long. To view the rest of the comments, please view the bug report online at http://bugs.php.net/21920 -- Edit this bug report at http://bugs.php.net/?id=21920&edit=1

« previous php.doc (#969359990) next »