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

From: Date: Mon, 08 Oct 2018 08:56:36 +0000
Subject: Doc #76971 [Csd]: Changed array append behaviour of array_unique
References: 1  Groups: php.doc.bugs 
Request: Send a blank email to doc-bugs+get-16057@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: Closed Type: Documentation Problem Package: Arrays related Operating System: Linux PHP Version: 7.2.10 Assigned To: cmb Block user comment: N Private report: N New Comment: Thank you. :) Previous Comments: ------------------------------------------------------------------------ [2018-10-06 11:44:07] cmb@php.net This bug has been fixed in the documentation's XML sources. Since the online and downloadable versions of the documentation need some time to get updated, we would like to ask you to be a bit patient. Thank you for the report, and for helping us make our documentation better. ------------------------------------------------------------------------ [2018-10-06 11:43:30] cmb@php.net Automatic comment from SVN on behalf of cmb Revision: http://svn.php.net/viewvc/?view=revision&amp;revision=345783 Log: Fix #76971: Changed array append behaviour of array_unique ------------------------------------------------------------------------ [2018-10-05 07:20:56] bjoern dot fischer at dezem dot de 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. ------------------------------------------------------------------------ [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 (#16057) next »