Skip to content

Conversation

vlakoff
Copy link
Contributor

@vlakoff vlakoff commented Jul 5, 2020

Doing some investigations after looking at this Stack Overflow question, this Laravel PR and this RFC for PHP 8, I noticed the following with current Laravel code:

Str::startsWith('haystack', ''); // false
Str::startsWith('', '');         // false

Str::endsWith('haystack', '');   // false
Str::endsWith('', '');           // true, should be false

Str::contains('haystack', '');   // false
Str::contains('', '');           // false

Hence this PR to make Str::endsWith more consistent, and to add tests for this case.

Also refs #2628.

On a related note: most other languages (Java, .NET, Python...), and even future PHP 8, return true when the needle is an empty string.

@taylorotwell taylorotwell merged commit 617d03c into laravel:7.x Jul 6, 2020
@vlakoff vlakoff deleted the str-endsWith branch March 7, 2025 15:27
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

Successfully merging this pull request may close these issues.

2 participants