Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion illuminate/Collections/Collection.php
Original file line number Diff line number Diff line change
Expand Up @@ -1688,7 +1688,11 @@ public function undot()
public function unique($key = null, $strict = false)
{
if ($key === null && $strict === false) {
return new static(\array_unique($this->items, \func_get_args()[2] ?? SORT_REGULAR));
$flags = \func_get_args()[2] ?? SORT_REGULAR;

return new static(
SORT_REGULAR === $flags ? \arrayUniqueSortRegular($this->items) : \array_unique($this->items, $flags)
);
}

$callback = $this->valueRetriever($key);
Expand Down
2 changes: 1 addition & 1 deletion illuminate/Foundation/Application.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ class Application extends Container implements
*
* @var string
*/
public const VERSION = '10.51.17';
public const VERSION = '10.51.18';

/**
* The base path for the Laravel installation.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public function register()
$events = $this->getEvents();

foreach ($events as $event => $listeners) {
foreach (array_unique($listeners, SORT_REGULAR) as $listener) {
foreach (\arrayUniqueSortRegular($listeners) as $listener) {
Event::listen($event, $listener);
}
}
Expand Down
51 changes: 51 additions & 0 deletions illuminate/Foundation/helpers.php
Original file line number Diff line number Diff line change
Expand Up @@ -1029,3 +1029,54 @@ function view($view = null, $data = [], $mergeData = [])
return $factory->make($view, $data, $mergeData);
}
}

if (!\function_exists('arrayUniqueSortRegular')) {
/**
* Backward compatible array_unique($items, SORT_REGULAR) fix
* see https://github.com/php/php-src/issues/20262#issuecomment-3441217772
* see https://github.com/laravel/framework/pull/57501#issuecomment-3441380946
*/
function arrayUniqueSortRegular(array $items): array
{
$ui = $us = $u = $sp = [];

foreach ($items as $k => $v) {
if (\is_string($v)) {
$us[$v] ??= $k;

continue;
}

if (\is_int($v)) {
$ui[$v] ??= $k;

continue;
}

if (null === $v) {
$sp['null'] ??= $k;

continue;
}

if (false === $v) {
$sp['false'] ??= $k;

continue;
}

if (true === $v) {
$sp['true'] ??= $k;

continue;
}

$u[$k] = $v;
}

return \array_intersect_key(
$items,
\array_flip($ui) + \array_flip($us) + \array_flip($sp) + \array_unique($u, SORT_REGULAR)
);
}
}
2 changes: 1 addition & 1 deletion src/Application.php
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ public function bootstrapRouter()
*/
public function version()
{
return 'Maravel Framework 10.51.17';
return 'Maravel Framework 10.51.18';
}

/**
Expand Down
51 changes: 51 additions & 0 deletions src/helpers.php
Original file line number Diff line number Diff line change
Expand Up @@ -433,3 +433,54 @@ function view($view = null, $data = [], $mergeData = [])
return $factory->make($view, $data, $mergeData);
}
}

if (!\function_exists('arrayUniqueSortRegular')) {
/**
* Backward compatible array_unique($items, SORT_REGULAR) fix
* see https://github.com/php/php-src/issues/20262#issuecomment-3441217772
* see https://github.com/laravel/framework/pull/57501#issuecomment-3441380946
*/
function arrayUniqueSortRegular(array $items): array
{
$ui = $us = $u = $sp = [];

foreach ($items as $k => $v) {
if (\is_string($v)) {
$us[$v] ??= $k;

continue;
}

if (\is_int($v)) {
$ui[$v] ??= $k;

continue;
}

if (null === $v) {
$sp['null'] ??= $k;

continue;
}

if (false === $v) {
$sp['false'] ??= $k;

continue;
}

if (true === $v) {
$sp['true'] ??= $k;

continue;
}

$u[$k] = $v;
}

return \array_intersect_key(
$items,
\array_flip($ui) + \array_flip($us) + \array_flip($sp) + \array_unique($u, SORT_REGULAR)
);
}
}