Skip to content

Improve error_handing replacement functions #6048

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 1 commit into from

Conversation

twose
Copy link
Member

@twose twose commented Aug 27, 2020

It looks that it's unnecessary to make user_error_handler UNDEF.
The usage of zend_replace_error_handling() is to convert warnings to exceptions, it does not involve the call to user_error_handler.

And it also breaks the security of coroutine switching, following is an example:

// 0
set_error_handler(function () {
    // 9
    var_dump(func_get_args());
});

// 1
$wr = new WaitReference();

// 2
Coroutine::run(function () use ($wr) {
    // 3
    // zend_replace_error_handling() was called
    // then stream_connect() was called
    // it yield from __construct
    new PDO('mysql:host=127.0.0.1;charset=utf8', 'root', 'root');
    // 6
});

// error handler is UNDEF here
// 4
trigger_error('foo', E_USER_WARNING);

// 5
// it's same with WaitGroup
$wr::wait($wr);
// 7

// 8
// after PDO __construct() done
// zend_restore_error_handling() was restored
// user error handler will be called
trigger_error('foo', E_USER_WARNING);

// 10

@nikic
Copy link
Member

nikic commented Aug 27, 2020

Hm, interesting... The thing is that we explicitly skip calls to user_error_handler in EH_THROW mode (so this change is fine), but I am wondering if we really should fully skip them. EH_THROW only converts warnings, not notices and deprecations. This means that calling of the user error handler will be skipped for them, which seems maybe not right?

@twose
Copy link
Member Author

twose commented Aug 27, 2020

Is it necessary to merge it into 7.3?
this patch will not break anything except struct zend_error_handling.

@twose
Copy link
Member Author

twose commented Aug 27, 2020

The use of EH_THROW is very limited...perhaps this is not a real problem.
It's a hack way, when we use this API, we should have considered its risks, in my opinion.

@twose
Copy link
Member Author

twose commented Aug 27, 2020

It's the new trend that throwing exceptions instead of warnings, I do hope we don’t use this API anymore... (Including other things that involve global vars)
Otherwise, the context switch of the coroutine will be affected.

@nikic
Copy link
Member

nikic commented Aug 27, 2020

@twose At least in this form, it cannot go into PHP 7.3 (it changes an exported structure). I think we should stick to master only.

@twose
Copy link
Member Author

twose commented Aug 27, 2020

It is a bugfix under the coroutine model...
it's better for me to merge it into PHP 7.3.
How about only merge the part of function implementation? it seems to have only benefits.
I am also glad to only merge it into master, but I am obligated to consider it for my users.

@nikic
Copy link
Member

nikic commented Aug 27, 2020

@twose Could you please submit another patch against PHP-7.3 to show how it would look like? I guess it should keep the structure the same but just always set the field to UNDEF.

@twose
Copy link
Member Author

twose commented Aug 30, 2020

Goto #6050

@twose twose closed this Aug 30, 2020
@twose twose deleted the error_handing branch August 30, 2020 11:47
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.

2 participants