Skip to content

Fix exceptions (PDOException) error code type #33713

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

Merged
merged 1 commit into from
Sep 26, 2019

Conversation

ed-fruty
Copy link

Q A
Branch? 4.3
Bug fix? yes
New feature? no
Deprecations? no
Tickets Fix #33704
License MIT

From the php.net docs Exception::getCode() description:

Returns the exception code as integer in Exception but possibly as other type in Exception descendants (for example as string in PDOException).

So if can be string, we convert it to the int in the HandlerFailedException but it still string in nestedExceptiions.

Copy link
Member

@fabpot fabpot left a comment

Choose a reason for hiding this comment

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

If the code can be a string, maybe we can change the type hint and allow a string everywhere? Casting to a string means that strings will always be converted to 0, right? Not sure if this is a problem though.

@ed-fruty
Copy link
Author

We can't allow string type.

php -a
php > $e = new Exception('message', 'string');

PHP Warning:  Uncaught Error: Wrong parameters for Exception([string $message [, long $code [, Throwable $previous = NULL]]]) in php shell code:1
Stack trace:
#0 php shell code(1): Exception->__construct('message', 'string')
#1 {main}
  thrown in php shell code on line 1

PHP does not allow it.

@fabpot
Copy link
Member

fabpot commented Sep 26, 2019

Thank you @ed-fruty.

fabpot added a commit that referenced this pull request Sep 26, 2019
This PR was squashed before being merged into the 4.3 branch (closes #33713).

Discussion
----------

Fix exceptions (PDOException) error code type

| Q             | A
| ------------- | ---
| Branch?       | 4.3
| Bug fix?      | yes
| New feature?  | no
| Deprecations? | no
| Tickets       | Fix #33704
| License       | MIT

From the [php.net docs](https://www.php.net/manual/en/exception.getcode.php) `Exception::getCode()` description:

> Returns the exception code as integer in Exception but possibly as other type in Exception descendants (for example as **string** in PDOException).

So if can be string, we convert it to the int in the `HandlerFailedException` but it still string in `nestedExceptiions`.

Commits
-------

9efa025 Fix exceptions (PDOException) error code type
@fabpot fabpot merged commit 9efa025 into symfony:4.3 Sep 26, 2019
@fabpot fabpot mentioned this pull request Oct 7, 2019
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