Skip to content

[12.x] Use array_first and array_last polyfills #56703

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Aug 21, 2025
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
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@
"symfony/mime": "^7.2.0",
"symfony/polyfill-php83": "^1.31",
"symfony/polyfill-php84": "^1.31",
"symfony/polyfill-php85": "^1.31",
"symfony/polyfill-php85": "^1.33",
"symfony/process": "^7.2.0",
"symfony/routing": "^7.2.0",
"symfony/uid": "^7.2.0",
Expand Down
6 changes: 5 additions & 1 deletion src/Illuminate/Collections/Arr.php
Original file line number Diff line number Diff line change
Expand Up @@ -256,6 +256,10 @@ public static function first($array, ?callable $callback = null, $default = null
return value($default);
}

if (is_array($array)) {
return array_first($array);
}

foreach ($array as $item) {
return $item;
}
Expand Down Expand Up @@ -283,7 +287,7 @@ public static function first($array, ?callable $callback = null, $default = null
public static function last($array, ?callable $callback = null, $default = null)
{
if (is_null($callback)) {
return empty($array) ? value($default) : end($array);
return empty($array) ? value($default) : array_last($array);
}

return static::first(array_reverse($array, true), $callback, $default);
Expand Down
3 changes: 2 additions & 1 deletion src/Illuminate/Testing/Constraints/HasInDatabase.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ class HasInDatabase extends Constraint
*
* @param \Illuminate\Database\Connection $database
* @param array<string, mixed> $data
* @return void
*/
public function __construct(Connection $database, array $data)
{
Expand Down Expand Up @@ -81,7 +82,7 @@ protected function getAdditionalInfo($table)

$similarResults = $query->where(
array_key_first($this->data),
$this->data[array_key_first($this->data)]
array_first($this->data),
)->select(array_keys($this->data))->limit($this->show)->get();

if ($similarResults->isNotEmpty()) {
Expand Down