-
-
Notifications
You must be signed in to change notification settings - Fork 2k
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
[NFR][PHP 7]beforeThrowable, beforeError in dispatcher #12289
Comments
Dont think this is necessary. Just update all exceptions to throwables when 4.0 is ready --- although this is way down the road. |
But 4.0 will be like in few years and for now this means we don't have way to handle errors in framework, otherwise than set_error_handler in php. |
So please change it to 3.1.0 maybe @sergeyklay because i want add this to 3.1.0 |
@Jurigag Could you please explain a bit more. Provide pseudocode |
You can still handle errors manually Jurigag. Changing the framework will break backwards compatibility. This should be implemented in dispatcher as well as across the board for all pieces of code when Phalcon goes minimum of PHP7. I'm not sure what milestone this will be ... maybe a year out or so with v4 or v5. Right now.. you can simply |
No, it won't break a framework. $eventsManager->attach('dispatcher:beforeException', function(Event $event, Dispatcher $dispatcer, Exception $exception) {
// handle exceptions only
});
$eventsManager->attach('dispatcher:beforeThrowable', function(Event $event, Dispatcher $dispatcer, Throwable $throwable) {
// handle throwables only
});
$eventsManager->attach('dispatcher:beforError', function(Event $event, Dispatcher $dispatcer, Error $throwable) {
// handle errors only
}); https://github.com/phalcon/cphalcon/blob/master/phalcon/dispatcher.zep#L341 change to:
Similar code(in php) is working without any breaking stuff both in php5 and php7. Just if class don't exist it's ignored. Not sure about zephir though - if it's the same then no problem, the problem will be if it can't compile. But will see, maybe some comment to detect php version if it will be problem ? I would just create a pr and do tests to prove it would work on both php versions without any problem, but don't want to do it on 3.0.x and then deal with rebasing etc on 3.1.x. And when we will support only php7 just remove there you can check - http://sandbox.onlinephpfunctions.com/code/35ea592f8ed7f57da4bfa76a570f8393ac784bdf this code works both on php5 and php7 without any errors or issues. |
Juri, this is the wrong solution. Your solution hurts performance. Correct solution is to handle this everywhere in code without extra handle event checks, upgrading all exceptions to throwables. This can be done in subsequent PHP7 only milestone. |
How it hurts performance ? |
These checks to handle instanceof should be done in application land ... not core land. I have benchmarks since I've already rewritten the dispatcher in my current branch because your latest updates to dispatcher have broken in on 3.x PHP5.6 |
http://sandbox.onlinephpfunctions.com/code/cd17232774263b56a486dadcde0445144a3bc547 |
It's also the wrong approach for solving this issue. It's a specific use-case in your situation, but it needs to be applied globally .. which will be handled later |
Not it shouldn't. It's already handled in framework for exception so why not errors and throwables ? I don't quite understand. How it's wrong approach ? Then why there is beforeException in first place ? |
So this issue can be closed and a new one to make Phalcon support PHP7 only can be created. |
Because ? You wrote it ? As i wrote - it can be done without literally no performance degredation to support both php5 and php7. Only php7 will be after few years, so for few years no built-in option to handle errors in throwables in framework ? This is kind of bad. |
We're not going to mix in more if/else/instanceof checks to handle situations for specific versions in code Phalcon code. Not going to happen. Zephir -- we'll use macros. Not in Phalconland. We avoid this by minimum compatibility and upgrading the core application as necessary. When Phalcon drops php5 support, throwables will be supported then. You can handle this manually now with no change to the application. So like I said, this can be closed. |
But there will be no if/else/instanceof check for SPECIFIC VERSIONS. |
function(Event $event, Dispatcher $dispatcer, Throwable $throwable) { will throw exception in zephir for php 5 |
} catch \Throwable, e { the same |
Well ... at a minimum it introduces ambiguity that should be handled globally since we handle exceptions everywhere. |
And the signature will change breaking BC so it should be a major release and this change should be applied across board for all exceptions like I said earlier. |
function(Event $event, Dispatcher $dispatcer, Throwable $throwable) { you will just not add this for php 5 anway because Throwable don't exist in php 5
Well, it's not my problem if zephir don't support this. Just in php you can do catch Throwable in php5, it will work without any problem |
This is why this is 4.0.0 milestone |
No, 4.0.0 milestone is this: Just only beforeThrowable. If we need change zephir to make it supporting both versions then we sure should do it surely. |
We cant implement beforeThrowable now. We cant use Throwable in Zephir for PHP 5 |
Yes we can - https://travis-ci.org/phalcon/cphalcon/builds/165241576 PHP 5.x is totally fine with this, php7 is seg faulting during tests, will check in home. |
Oh yes, as I can see - this problem was recently solved in Zephir project |
Closing in favor of #13855. Will revisit if the community votes for it, or in later versions. |
In php 7 there was added
Throwable
interface. We need to in dispatcher and micro, add option to catch throwable(so errors too). Im thinking how to do this exactly, there is my idea:beforeThrowable
and catch allThrowable
, if there is some handler attached to this event then use itbeforeException
, so current code will keep working but throw errors onlybeforeError
event to catch only errors - so we don't need to change any code we have currently withbeforeException
and we can add code to catchError
onlySo in result no code changes will be needed if we don't care about errors in php 7 or our application will not produce them. If we want add support for it we can either switch
beforeException
tobeforeThrowable
with current code or just add newattach
forbeforeError
with new handler for it.The text was updated successfully, but these errors were encountered: