Both sides previous revisionPrevious revisionNext revision | Previous revision |
rfc:consistent_type_errors [2019/02/19 09:52] – Start voting nikic | rfc:consistent_type_errors [2019/03/11 10:36] (current) – Implemented nikic |
---|
* Date: 2019-02-05 | * Date: 2019-02-05 |
* Author: Nikita Popov <nikic@php.net> | * Author: Nikita Popov <nikic@php.net> |
* Status: Voting | * Status: Implemented (in PHP 8.0) |
* Target Version: PHP 8.0 | |
* Implementation: https://github.com/php/php-src/pull/3794 | * Implementation: https://github.com/php/php-src/pull/3794 |
| |
Additionally, some functions opt-in to always generate a ''TypeError'', regardless of ''strict_types'' setting. This is the case for all constructors, because they do not have a meaningful way of returning a null value. Other functions, such as ''random_int'', or the entirety of the sodium extension, also opt-in to throwing. Newly introduced methods will often do so in order to consistently throw exceptions for all their error conditions. | Additionally, some functions opt-in to always generate a ''TypeError'', regardless of ''strict_types'' setting. This is the case for all constructors, because they do not have a meaningful way of returning a null value. Other functions, such as ''random_int'', or the entirety of the sodium extension, also opt-in to throwing. Newly introduced methods will often do so in order to consistently throw exceptions for all their error conditions. |
| |
Finally, the manner in which the error is reported depends on which mechanism detected the violation. The above description applies to the ''zend_parse_parameters''/''ZEND_PARSE_PARAMETERS'' APIs typically used by internal functions. However, functions can additional specify argument information (which is made available through reflection). If the argument information specifies types, then violation of those will always result in a ''TypeError''. | Finally, the manner in which the error is reported depends on which mechanism detected the violation. The above description applies to the ''zend_parse_parameters''/''ZEND_PARSE_PARAMETERS'' APIs typically used by internal functions. However, functions can additionally specify argument information (which is made available through reflection). If the argument information specifies types, then violation of those will always result in a ''TypeError''. |
| |
This can lead to peculiar situations where the error behavior will depend on which argument is invalid: | This can lead to peculiar situations where the error behavior will depend on which argument is invalid: |
Voting opened 2019-02-19 and closes 2019-03-05. A 2/3 majority is required to pass. | Voting opened 2019-02-19 and closes 2019-03-05. A 2/3 majority is required to pass. |
| |
<doodle title="Make zpp failures always throw TypeError?" auth="nikic" voteType="single" closed="false"> | <doodle title="Make zpp failures always throw TypeError?" auth="nikic" voteType="single" closed="true"> |
* Yes | * Yes |
* No | * No |
</doodle> | </doodle> |