-
Notifications
You must be signed in to change notification settings - Fork 11.2k
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
[7.x] Add split() to Stringable class #32713
Conversation
I think you will need to first add this method to the Str class. |
*/ | ||
public function split($pattern, $limit = -1, $flags = 0) | ||
{ | ||
$keywords = preg_split($pattern, $this->value, $limit, $flags); |
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 about error handling?
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.
preg_split
returns false
on failing
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.
Yes, and then you hide the error? Fail doesn't mean no matches, it means that the pattern was invalid, but you hide this.
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.
Ok get it! What's the recommended handling in this case? Removing the condition? Errors seem to be ignored for most methods
eg:
preg_match_all($pattern, $this->value, $matches); |
As it was similar to |
Add a
split()
method to Stringable as a proxy topreg_split()
to allow splitting by regex in addition ofexplode()
Example