Doc #76971 [Ver]: Changed array append behaviour of array_unique

From: Date: Fri, 05 Oct 2018 07:20:56 +0000
Subject: Doc #76971 [Ver]: Changed array append behaviour of array_unique
References: 1  Groups: php.doc.bugs 
Request: Send a blank email to doc-bugs+get-16047@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=76971&edit=1 ID: 76971 User updated by: bjoern dot fischer at dezem dot de Reported by: bjoern dot fischer at dezem dot de Summary: Changed array append behaviour of array_unique Status: Verified Type: Documentation Problem Package: Arrays related Operating System: Linux PHP Version: 7.2.10 Block user comment: N Private report: N New Comment: Ok, I get why this changed and it actually is be the behaviour that I would have expected in the first place. But it should still be documented that the behaviour of this function changed. So that people can know why their code breaks. Previous Comments: ------------------------------------------------------------------------ [2018-10-04 17:47:48] cmb@php.net This behavioral change is caused by an optimization which only affects SORT_STRING mode[1]. Formerly the array has been copied and then non-unique elements have been deleted (without packing the array afterwards). Now a new array is built by adding the unique elements. Obiously, this can lead to different numeric indexes. [1] <http://git.php.net/?p=php-src.git;a=commit;h=6c2c7a023da4223e41fea0225c51a417fc8eb10d> ------------------------------------------------------------------------ [2018-10-04 13:37:38] bjoern dot fischer at dezem dot de Description: ------------ --- From manual page: http://www.php.net/function.array-unique --- Beginning with PHP-7.2 appending an element to an array, after calling array_unique, changed behaviour. Before, the internal array-index-pointer was unchanged after calling array_unique, now with PHP 7.2 the array-index-pointer is set to the last remaining array element. This should be documented. This can be tested here: https://3v4l.org/IdmUX Test script: --------------- <?php $a = [0, 1, 2, 3, 3, 3]; $b = array_unique($a); $b[] = 4; var_dump($b); ------------------------------------------------------------------------ -- Edit this bug report at https://bugs.php.net/bug.php?id=76971&edit=1

« previous php.doc.bugs (#16047) next »