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

PDO: Raise a proper exception if user or password is false #6513

Merged
merged 1 commit into from
Sep 2, 2024

Conversation

derrabus
Copy link
Member

@derrabus derrabus commented Aug 30, 2024

Q A
Type bug
Fixed issues #6512

Summary

If false (or anything that is not a string) is passed as user or password, we run into a TypeError because we pass that value as-is to the constructor of PDO. This started to happen after we enabled strict types on our driver classes in 4.0.

On 3.9, false would implicitly be cast to an empty string which is either desired or leads to more obscure connection errors. We could restore the behavior of 3.9 by adding explicit type casts to the two parameters. But since we don't document false as a valid value for either parameter, my preference would indeed be raising an exception.

@derrabus derrabus changed the title PDO: Raise a proper exception is user or password is false PDO: Raise a proper exception if user or password is false Aug 30, 2024
@derrabus derrabus added this to the 4.1.1 milestone Aug 30, 2024
greg0ire
greg0ire previously approved these changes Aug 30, 2024
public static function notAStringOrNull(string $key, mixed $value): self
{
return new self(sprintf(
'The %s configuration setting is expected to be either a string or null, got %s.',
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd use "configuration parameter" instead of "configuration setting" for consistency with the existing terminology. We use "params" / "parameters" a lot at least in the code.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you. I've adjusted the wording.

@derrabus derrabus merged commit ab82363 into doctrine:4.1.x Sep 2, 2024
78 of 79 checks passed
@derrabus derrabus deleted the bugfix/user-is-false branch September 2, 2024 15:02
derrabus added a commit that referenced this pull request Sep 3, 2024
* 4.1.x:
  PDO: Raise a proper exception if user or password is false (#6513)
derrabus added a commit that referenced this pull request Sep 3, 2024
* 4.2.x:
  PDO: Raise a proper exception if user or password is false (#6513)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants