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
- 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 the following example. Specifically, the following members are proposed to be modified:
- Throwable::getCode(): mixed; - Error ::construct(string $message = “”, /* mixed */ $code = 0, Throwable $previous = null); - Exception::construct(string $message = “”, /* mixed */ $code = 0, Throwable $previous = null); - Error ::$code : mixed; - Exception::$code : mixed;
Backward Incompatible Changes
None.
Proposed PHP Version(s)
Next minor version, currently 7.2.
Proposed Voting Choices
Future Scope
Patches and Tests
N/A
References
N/A