rfc:throwable-code-generalization
This is an old revision of the document!
PHP RFC: Throwable error code's type generalization
- Version: 0.1
- Date: 2016-12-18
- Author: Wes (@WesNetmo on Twitter)
- Status: Under Discussion
- First Published at: http://wiki.php.net/rfc/throwable-code-generalization
Introduction
Currently Exception::$code
, Error::$code
and Throwable::getCode()
are only allowed to be int
, but this is limiting and in fact it is even violated by PHP itself, specifically by the PDO extension (whose error codes are actually strings).
Proposal
Allow any type to be used, including objects, even if just formally, because they technically already allow other types to be used, as shown in this example. Specifically, the following members are proposed to be modified:
Throwable::getCode() /* mixed */
Error ::construct(string $message = “”, /* mixed */ $code = 0, Throwable $previous = null);
Error ::$code /* mixed */;*
Exception::construct(string $message = “”, /* mixed */ $code = 0, Throwable $previous = null); **
Exception::$code /* mixed */;===== Backward Incompatible Changes ===== None. ===== Proposed PHP Version(s) ===== Next minor version, currently 7.2. ===== Future Scope ===== Will come in handy when PHP will support structures like
Enums,
EnumSet''s, etc.
Proposed Voting Choices
Accept “Throwable error code's type generalization”? Will require 50% + 1.
Patches and Tests
N/A
References
N/A
rfc/throwable-code-generalization.1482052460.txt.gz · Last modified: 2017/09/22 13:28 (external edit)