Skip to content
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

Convert SPL Exception usage to normal Error #4992

Closed
wants to merge 13 commits into from

Conversation

Girgias
Copy link
Member

@Girgias Girgias commented Dec 8, 2019

It seems to be me that it is wiser to convert those Exceptions to (Type|ArgumentCount|Value)Error then to leave the SPL Exceptions.

Thoughts?

@Girgias Girgias marked this pull request as ready for review December 9, 2019 01:56
@Girgias Girgias changed the title [WIP] Convert SPL Exception usage to normal Error Convert SPL Exception usage to normal Error Dec 9, 2019
@Girgias
Copy link
Member Author

Girgias commented Dec 30, 2019

If there are no objections I'll merge this in a week.

@nikic
Copy link
Member

nikic commented Jan 3, 2020

@cmb69 @kocsismate Any thoughts on the general idea here? Changing existing exception types seems somewhat more problematic from a BC perspective to me, and not sure it really buys us much.

@kocsismate
Copy link
Member

kocsismate commented Jan 3, 2020

At the first sight, this change seemed too risky for me, but I am wondering if it is really the case:

As far as I saw, these are programming errors. Thus, I would be surprised if people caught the thrown exceptions "directly".

What it means for me is that it might not matter much for the end users what kind of exception is actually thrown... And as people already have to have a general error handler (catching Throwables) since years, we wouldn't even risk their production system by throwing previously uncatchable/unknown exceptions.

@Girgias Girgias force-pushed the spl-use-standard-exception branch 2 times, most recently from d402fb3 to 9869eb9 Compare January 7, 2020 17:18
}
if (error) {
efree(error);
}
zend_string_release_ex(func_name, 0);
RETURN_FALSE;
return;
Copy link
Member

@kocsismate kocsismate Jan 7, 2020

Choose a reason for hiding this comment

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

All these returns should be RETURN_THROWS() ideally. See #5036

Copy link
Member Author

Choose a reason for hiding this comment

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

Huh, I though that you went through them that's why I needed to manually fix the merge conflicts. Will do the remaining ones

Copy link
Member

Choose a reason for hiding this comment

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

Ah, no, please ignore. I didn't add RETURN_THROWS() previously myself here, because it's not sure that an exception is thrown. But then what is the purpose of changing the return type?

Copy link
Member Author

Choose a reason for hiding this comment

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

I didn't look at the specific case until I opened my editor. But yeah now I'm not sure why I changed the return type ...

Copy link
Member

Choose a reason for hiding this comment

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

Maybe

if (do_throw) {
    RETURN_THROWS();
} else {
    RETURN_FALSE;
}

Copy link
Member Author

Choose a reason for hiding this comment

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

I think I've covered all the case, please let me know if there are some that I missed.

Copy link
Member

@kocsismate kocsismate Jan 7, 2020

Choose a reason for hiding this comment

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

For me, the PR itself looks fine (apart from the few issues with RETURN_THROWS()), but we should try to address Nikita's concern. :)

ext/spl/spl_fixedarray.c Outdated Show resolved Hide resolved
@Girgias
Copy link
Member Author

Girgias commented Jan 27, 2020

Should I move forwards with this, post on internals, or drop this change?

@Girgias
Copy link
Member Author

Girgias commented Feb 25, 2020

Any other opinions?

@cmb69
Copy link
Member

cmb69 commented Mar 25, 2020

Thinking about this, it seems to me that it's more of a problem that we still support some of these exceptions not to be thrown at all (spl_autoload_register(…, false)). While that may have made sense when the function had been introduced, I don't think it makes sense for PHP 8, where most other functions now throw (instead of warn) on illegal input. I think I'd start there.

@Girgias
Copy link
Member Author

Girgias commented Mar 25, 2020

Thinking about this, it seems to me that it's more of a problem that we still support some of these exceptions not to be thrown at all (spl_autoload_register(…, false)). While that may have made sense when the function had been introduced, I don't think it makes sense for PHP 8, where most other functions now throw (instead of warn) on illegal input. I think I'd start there.

SPL is truly an interesting extension, I didn't even know you could do that. Are there only a couple of function which toggle this behaviour, and if so is there a list? (could always read the docs to get an idea of haw many there are ...)

@cmb69
Copy link
Member

cmb69 commented Mar 25, 2020

spl_autoload_register() may be the only such function. (And yes, SPL is "interesting".)

@Girgias
Copy link
Member Author

Girgias commented Apr 17, 2020

I've made some conversions too while I was updating the errors to the new format, don't know if I should have split or not but the easiest would be to split per Class if needed.

@kocsismate can you have a look at the error messages?

Also still need to do iterators and observers classes.

@kocsismate
Copy link
Member

kocsismate commented Apr 17, 2020

@Girgias I'll have a look for sure! However, I think we should first decide if we can really change the exceptions to errors. @nikic? @cmb69? I for one would be in favour, because this is what we use everywhere (with the exception of sodium, as far as I can tell).

However, I don't know much about the BC implications... My guess is that the change wouldn't be very problematic, since I would expect that people generally don't catch InvalidArgumentExceptions separately... (but just in the outmost exception handler)

@cmb69
Copy link
Member

cmb69 commented Apr 17, 2020

Well, we also have to consider existing test suites; I'm not sure that changing the exception types is a good idea for now.

@kocsismate
Copy link
Member

kocsismate commented Apr 17, 2020

we also have to consider existing test suites

Yes, that makes sense. In this case, some of the zend_(type|value)_error() invocations could be changed to zend_argument_error(exception_ce, ...)

@Girgias
Copy link
Member Author

Girgias commented Sep 3, 2020

Closing because this is old and rebasing it is a bit of a PITA. Might reopen a similar one just converting Uninitialized/already initialized objects to a standard Error.

@Girgias Girgias closed this Sep 3, 2020
@Girgias Girgias deleted the spl-use-standard-exception branch September 3, 2020 15:32
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.

4 participants