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 this 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.

Future Scope

Will come in handy when PHP will support structures like Enums, EnumSets, 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.1482052486.txt.gz · Last modified: 2017/09/22 13:28 (external edit)