Skip to content
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

Standardize Str::startsWith() and endsWith() with empty needle #2627

Closed
vlakoff opened this issue Nov 3, 2013 · 2 comments
Closed

Standardize Str::startsWith() and endsWith() with empty needle #2627

vlakoff opened this issue Nov 3, 2013 · 2 comments

Comments

@vlakoff
Copy link
Contributor

vlakoff commented Nov 3, 2013

Currently, starts_with('foobar', '') throws a warning (and returns false) and ends_with('foobar', '') returns true.

I think the warning should be removed, and the return value of these cases unified.

And, per this answer on stackoverflow:
Java and .NET implementations of String.StartsWith and String.EndsWith return true if needle is an empty string.

@vlakoff
Copy link
Contributor Author

vlakoff commented Nov 3, 2013

Also, for the curious: why it returns true.

@vlakoff
Copy link
Contributor Author

vlakoff commented Nov 3, 2013

Str::contains('foobar', '') could be fixed similarly. It currently produces a warning.

Please note that PHP function strpos('foobar', '') produce a warning, contrarily to Java and .NET 's indexOf() which return true.

So, we have two solutions for Laravel's contains(), startsWith() and endsWith():

  • Act like PHP and don't support empty needles
  • Act like Java and .NET and return true. PHP's strpos() being the exception.

Your opinion on this?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants