Skip to content

Fix Throwable::getCode() method return type #680

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 3 commits into from

Conversation

akondas
Copy link
Contributor

@akondas akondas commented Sep 21, 2021

@orklah
Copy link
Contributor

orklah commented Sep 21, 2021

This is not accurate. PDOException will return a string to getCode(), which means

try{
    throwsPDOException();
}
catch(Exception $e){
   var_dump($e->getCode());
}

will display a string for Exception::getCode()

@akondas
Copy link
Contributor Author

akondas commented Sep 21, 2021

Oh, I wasn't aware of that ... this should not be possible since you are excepting \Exception, thanks PHP

@orklah
Copy link
Contributor

orklah commented Sep 21, 2021

Well, the doc is actually incorrect, getCode returns int|string. However, in 99% of usages, it will return int, so I guess it was decided not to confuse people reading the doc. But yeah, this is something to consider when tweaking with static analysis tools

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.

Throwable::getCode() should always return int instead of mixed
3 participants