Both sides previous revisionPrevious revisionNext revision | Previous revisionNext revisionBoth sides next revision |
rfc:throwable-code-generalization [2017/01/05 21:33] – wesnetmo | rfc:throwable-code-generalization [2017/01/10 14:46] – wesnetmo |
---|
* Date: 2016-12-18 | * Date: 2016-12-18 |
* Author: Wes (@WesNetmo on Twitter) | * Author: Wes (@WesNetmo on Twitter) |
* Status: Under Discussion | * Status: On Hold because of ML problems |
* First Published at: http://wiki.php.net/rfc/throwable-code-generalization | * First Published at: http://wiki.php.net/rfc/throwable-code-generalization |
| |
===== Introduction ===== | ===== Introduction ===== |
| |
Currently ''Exception::$code'', ''Error::$code'' and ''Throwable::getCode()'' are said to be ''int'' only, but this is actually violated by PHP itself, specifically by the PDO extension, whose error codes are instead strings. | Currently ''Exception::$code'', ''Error::$code'' and ''Throwable::getCode()'' are said to be ''int'' only, but this is actually violated by PHP itself, specifically by the PDO extension, whose error codes are strings instead. |
| |
As such, code that assumes that the interface always uses ''int'' is already potentially broken - because it doesn't special-case PDO - or it does already special-case the type so that PDO's errors don't create issues. | As such, code that assumes that the interface always uses ''int'' is already potentially broken - because it doesn't special-case PDO - or it does already special-case the type so that PDO's errors don't create issues. |
===== Proposal ===== | ===== Proposal ===== |
| |
As this inconsistency is present, this RFC proposes to generalize the Throwable's code so that it can be of any type - not just ''int''. In practice this is mostly a documentation change because the ''int'' type is currently almost [[https://3v4l.org/BoF4U|not actually enforced]]. | As this inconsistency is present, this RFC proposes to generalize the Throwable's code so that it can be of any type - not just ''int''. In practice this is mostly a documentation change because the ''int'' type is [[https://3v4l.org/BoF4U|never enforced]], except for ''Exception'' and ''Error'' constructors. |
| |
| Throwables' codes are normally not needed, and even if they were, numeric ones aren't comfortable to work with. Allowing any type can open up to new possibilities for this property that is currently almost useless, like Enum/EnumSet-like objects, strings, etc. |
| |
Specifically, the following members are proposed to be modified: | Specifically, the following members are proposed to be modified: |
* ''protected mixed Error::$code;'' | * ''protected mixed Error::$code;'' |
* ''protected mixed Exception::$code;'' | * ''protected mixed Exception::$code;'' |
| |
Throwables' codes are normally not needed, and even if they were, numeric ones aren't comfortable to work with. Allowing any type can open up to new possibilities for this property that is currently almost useless, like Enum/EnumSet-like objects, strings, etc. | |
| |
===== Backward Incompatible Changes ===== | ===== Backward Incompatible Changes ===== |
| |
2/3 majority is required | 2/3 majority is required |
| |
| |
| |
===== Patches and Tests ===== | ===== Patches and Tests ===== |