rfc:throwable-code-generalization

This is an old revision of the document!


PHP RFC: Throwable error code's type 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

rfc/throwable-code-generalization.1482052002.txt.gz · Last modified: 2017/09/22 13:28 (external edit)