Skip to content

Allow passing false to the $length parameter of substr #7533

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

Closed
wants to merge 1 commit into from

Conversation

dunglas
Copy link
Member

@dunglas dunglas commented Sep 29, 2021

According to the documentation, it's possible to pass false as a value for the length parameter of the substr() function:

If length is given and is 0, false or null, an empty string will be returned.

However, when strict types are enabled, passing false currently throws the following error:

Fatal error: Uncaught TypeError: substr(): Argument #3 ($length) must be of type ?int, bool given

This causes a break in the dev version of Doctrine: doctrine/orm#8878

I wonder if we should fix the documentation or fix the code.
In this PR, I tried to fix the code, but as the test failure shows, changing the stub file isn't enough. We also have to add a slightly more heavy parameter parsing logic and I wonder if it is worth it.

What do you think?

Signed-off-by: Kévin Dunglas <kevin@dunglas.fr>
@dunglas
Copy link
Member Author

dunglas commented Sep 30, 2021

Fixed in Doctrine. Let's update the docs instead.

@dunglas dunglas closed this Sep 30, 2021
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.

1 participant