-
Notifications
You must be signed in to change notification settings - Fork 11.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
remove unnecessary foreach from is() method (#24872)
- Loading branch information
1 parent
23f6279
commit 57d7b1f
Showing
1 changed file
with
1 addition
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
57d7b1f
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this is causing aun issue
Will this stay like this?
issue: preg_quote() expects parameter 1 to be string, array given
57d7b1f
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
what are you providing as input to the
...$patterns
parameter?57d7b1f
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I had a production issue with it also. Previously I passed an array as a parameter, after the update I got the same error as @ortegon000 reported. Luckly I used it only in one place of the project so it was a minor outage.
57d7b1f
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it is a regression as in many places in the framework you can opt to use an array or rely on the spread operator, such as middleware only/expcet options, array helper funcions (eg. array_only), request only/except, and many other places.
I prefer to use arrays when passing this multiple arguments, just for personal preference, I can adjust my mindset, but maybe we need a test to avoid breaking apps with this kind of updates
57d7b1f
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
you code should not be affected by this change, because we normalize everything to an array when it comes in. I'm digging into this right now
57d7b1f
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The splat in the argument list wraps the array inside another array.
So previously if passing an array the
foreach
iterated through the outer array generated by the splat operator on argument list and passed the inner array to theStr::is(...)
which handles array arguments well.Without the
foreach
, the functions passes this double-array (outer and inner array) and then the error occurs, as theStr::is
iterates through the outer array and tries to handle the inner array as a string.It was an easy fix in my app, but maybe we should include a note on the docblock to not pass an array. The weirdst thing is that the
routeIs
method which is just below theis
method in theRequest
class and does not use theforeach
previously used in theis
method. By git blaming it, it was added much later and maybe is not so well know as its counterpart.57d7b1f
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The docblock already lists the parameter as
dynamic
, which is explicitly different fromarray|string
which is what your usage seems to suggest you were using it as.57d7b1f
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
absolutely right. I had to learn how the splat actually passes through.
here is the only documentation I could find for the method:
https://laravel.com/docs/5.6/requests#request-path-and-method
It is a little lacking, and doesn't even discuss checking multiple paths.
While going forward I would say it should be used dynamically, I would say this is a breaking change that should not have been merged in a point release.
57d7b1f
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I also am having an issue with this change. I'm passing in an array as I always have been and now it is throwing the error as mentioned before. It is adding my array inside another array. So it is now iterating through and trying to preg_quote an array.
57d7b1f
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi @philmareu , @browner12 already sent PR #24885 that reverts the change and it got merged. But it is not released yet. You can rollback to 5.6.27 while waiting for the next release to be tagged.