[PoC] [WIP] throw_legacy_failure declare statement#4549
[PoC] [WIP] throw_legacy_failure declare statement#4549Girgias wants to merge 1 commit intophp:masterfrom
Conversation
|
Perhaps following the JSON change on 7.3 and calling it |
|
|
||
| if (num_keys != num_values) { | ||
| php_error_docref(NULL, E_WARNING, "Both parameters should have an equal number of elements"); | ||
| php_exception_or_error_docref(NULL, E_WARNING, "Both parameters should have an equal number of elements"); |
There was a problem hiding this comment.
I believe it's okay to convert this kind of error condition to an Error unconditionally (I've been doing this occasionally). Basically any error condition that indicates a programming error and no reasonable code should handle locally.
For this kind of directive, I think the area to focus on would be things like I/O errors.
There was a problem hiding this comment.
Okay, what is the best way to convert these? Using zend_throw_exception(zend_ce_error_exception, message, E_ERROR); directly instead or is there a predefined function/macro for throwing ErrorExceptions?
There was a problem hiding this comment.
I personally think these are not strictly programmer errors, and could save us from an awful lot of boilerplate pre-validation code if e.g. the arrays are populated from some file or even a HTTP request.
But surely, anything catchable is of help.
|
I agree with @deleugpn that something along the lines of 👍 for the general idea, in any case. Thank you! |
I'll be changing it to that when I'll start working on that again. |
|
Closes this: an improved version is located at Girgias#2 |
This is a proof of concept for letting internal/old functions be able to throw an Exception in case of failure instead of using the legacy behaviour of returning
nullorfalse.This behaviour is controlled by the user on a per-file basis, as with
strict_types, using the following declare statement:declare(throw_legacy_failure=1);This declare statement is not meant to throw an Exception on valid
false/nullreturn values, e.g.strpos()returningfalsewhen the needle was not found in the string.A couple of question still remain:
FailureExceptionor more specialised exceptions per extension.