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\Arr
helpers were changed to use the newarray_first
andarray_last
functions 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-php85
package.The issue is, if a package requires the
laravel/helpers
package, it also definesarray_first
andarray_last
functions.Then if
laravel/helpers
gets loaded beforesymfony/polyfill-php85
the functions defined inlaravel/helpers
will 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_first
andarray_last
within 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_contains
function was first introduced in PHP 8.0, thelaravel/helpers
package 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_last
andstr_contains
helpers to avoid an infinite loop.