Skip to content

Previous error handler not callable #32758

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

tweichart
Copy link

Q A
Branch? 4.4
Bug fix? yes
New feature? no
BC breaks? no
Deprecations? no
Tests pass? yes
Fixed tickets -
License MIT
Doc PR -

Previous calls to the $previousHandler would have resulted in a fatal error (see e.g. ln 512 in Kernel.php), as a boolean value was saved to the $previousHandler variable due to the defined method. Check for method was left in place, now the actual error_handler method defined in the PHPUNIT_COMPOSER_INSTALL will be used in case of existence.
If-statement for resetting the error_handler was changed too, as there's no boolean in the variable anymore.
Apart from that a return; was changed to return null; as it won't throw errors in various cases but return the same result as before.

Tobias Weichart added 2 commits July 26, 2019 12:38
* previous calls to the previousHandler would have resulted in a fatal error
* boolean was saved to variable, which later would have been called in custom error_handler
* left check for previous existing error_Handler
* replaced result with the actually defined and callable error_handler function
* replaced empty return statement by null
@tweichart tweichart changed the title Errorhandler callable Previous error handler not callable Jul 26, 2019
@nicolas-grekas nicolas-grekas added this to the next milestone Jul 26, 2019
@nicolas-grekas
Copy link
Member

I'm sorry I don't get it. Can you please provide a reproducer script/app where I could see the fatal error happening?

@fancyweb
Copy link
Contributor

fancyweb commented Jul 26, 2019

IMHO, $previousHandler can be true and then it never goes in this set_error_handler or it equals the previous error handler (null or a callable).
So there is nothing to fix.

@tweichart
Copy link
Author

@nicolas-grekas I don't have a case or script where it fails, just having a look at the code reveals some sort of logic error here.

@fancyweb actually you could change the line
return $previousHandler ? $previousHandler($type, $message, $file, $line) : false; simply to return false; and the 'problem' would be gone. I wanted to keep the original logic found here though, as I wasn't quite sure about the impact that the removal would have...

@nicolas-grekas
Copy link
Member

@tweichart ok thank for the feedback. To me, there is no bug here, things are as expected. If you can provide a script producing the fatal error you see, I'd be happy to be wrong.

@fancyweb
Copy link
Contributor

fancyweb commented Jul 26, 2019

@tweichart cf https://3v4l.org/vYo1c

$previousHandler in the error handler will always be equals to the previous error handler, thus null or a callable.

PHPStorm reports that it's a bool but it's a wrong static analysis.

@tweichart
Copy link
Author

@fancyweb yes you're right, the $previousHandler($type, $message, $file, $line) will never be called. so a more proper fix would be to replace the return statement by a simple return false;, isn't it?
If it's ok to leave unused calls in the code it's fine with me, just wanted to clean up ;-)

@fancyweb
Copy link
Contributor

It can be called if there is a previous error handler (uncomment the set_error_handler(function () {});) in my previous link.

@xabbuh
Copy link
Member

xabbuh commented Jul 26, 2019

Even if it doesn't look so obvious, I am convinced that the current code works as expected. However, I have opened #32760 to rearrange some code that makes this more clear. What do you think?

@nicolas-grekas
Copy link
Member

Thanks @xabbuh
@tweichart please have a look at #32760 which provides the same logic as the current one, in a more readable way.

fabpot added a commit that referenced this pull request Jul 27, 2019
This PR was merged into the 4.2 branch.

Discussion
----------

[HttpKernel] clarify error handler restoring process

| Q             | A
| ------------- | ---
| Branch?       | 4.2
| Bug fix?      | no
| New feature?  | no
| BC breaks?    | no
| Deprecations? | no
| Tests pass?   | yes
| Fixed tickets | #32758
| License       | MIT
| Doc PR        |

Commits
-------

c1349d1 clarify error handler restoring process
@tweichart tweichart deleted the errorhandler_callable branch July 30, 2019 08:41
@nicolas-grekas nicolas-grekas modified the milestones: next, 4.4 Oct 27, 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.

5 participants