Skip to content

Parameter Validation + Exceptions (GD, Hash) #4559

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

Conversation

markrandall
Copy link

First attempt at contributing. Tests are not currently blessed, need to discuss the idea of php_error_parameter_validation to enforce formatting of information, or if exceptions should be thrown directly.

@markrandall markrandall changed the title Parameter Validation + Exceptions for GD Parameter Validation + Exceptions (GD, Hash) Aug 19, 2019
@cmb69
Copy link
Member

cmb69 commented Aug 20, 2019

Thanks for the PR! Indeed, something like this should be done to augment https://wiki.php.net/rfc/consistent_type_errors. I'm not sure about the details, though. Do we want a new API for this? Which kind of Error should be thrown? Anyhow, we should figure out the details, and apply the changes consistently accross the code base (see PR #4553, #4554 and #4566).

@markrandall
Copy link
Author

A standard certainly wouldn't hurt, maybe it's something we need to take to Internals? I've been in touch with GPB but we are taking slightly different approaches, mainly I'm going through a helper function that takes the parameter number.

@Girgias
Copy link
Member

Girgias commented Aug 20, 2019

From what @nikic told me TypeError and normal Error are the way to go now maybe adding an API is better to get some nice consistent messages like he did with the TypeError RFC?

@markrandall
Copy link
Author

I see a few main conditions:

  1. A parameter validation failure where the position is known (directly inside a PHP_FUNCTION or where the function internal params are passed).

  2. A parameter validation failure where the position is unknown (helper functions called from a PHP_FUNCTION).

  3. Errors relating to invalid state or global context, for example with sessions, many functions write warnings and return false if the session is active. This would seem to be a suitable candidate for converting to exceptions also.

The major problem here is going to be the test cases. Sooooo many test cases. Many of which would have different logic in a post-elevation scenario, particularly those that check for living after a bad function call.

@KalleZ
Copy link
Member

KalleZ commented Aug 20, 2019

I think this should be separate PRs (one for implementation) and subsequent ones for each extension or part converted.

As for the change itself, it is something that should at least be mentioned on the internals for a chance at feedback (I think its a fairly minimal change in itself so there should not be a need for the RFC process to be invoked here).

@markrandall
Copy link
Author

@KalleZ Thanks. I've kicked it over to Internals for a quick discussion on format and then I'll likely pull this PR and create a new one on a per-module basis.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants