Prevent infinite loop on array_first, array_last, str_contains #37
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Recently some
Illuminate\Collection\Arrhelpers were changed to use the newarray_firstandarray_lastfunctions introduced in PHP 8.5.These changes were introduced on PR laravel/framework#56706
Although PHP 8.5 is yet to be released, these changes were possible by requiring the
symfony/polyfill-php85package.The issue is, if a package requires the
laravel/helperspackage, it also definesarray_firstandarray_lastfunctions.Then if
laravel/helpersgets loaded beforesymfony/polyfill-php85the functions defined inlaravel/helperswill take precedence.And currently the definitions of these functions will create an infinite loop, as they both are just an alias to
Arr::first()andArr::last(), and those callarray_firstandarray_lastwithin their implementation.helpers/src/helpers.php
Lines 84 to 87 in bc28464
helpers/src/helpers.php
Lines 156 to 159 in bc28464
During the assessment for this PR, I noted that the
str_contains()helper can also result in an infinite loop.helpers/src/helpers.php
Lines 410 to 413 in bc28464
Although the native
str_containsfunction was first introduced in PHP 8.0, thelaravel/helperspackage supports PHP versions as old as PHP 7.2, so I thought of also handling this helper.This PR
Arr::first(),Arr::last()andStr::contains()directly into thearray_first,array_lastandstr_containshelpers to avoid an infinite loop.