rfc:throwable-code-generalization

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
rfc:throwable-code-generalization [2016/12/18 09:21] wesnetmorfc:throwable-code-generalization [2017/09/22 13:28] (current) – external edit 127.0.0.1
Line 4: Line 4:
   * Date: 2016-12-18   * Date: 2016-12-18
   * Author: Wes (@WesNetmo on Twitter)   * Author: Wes (@WesNetmo on Twitter)
-  * Status: Under Discussion+  * Status: Declined
   * 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 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).+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 extensionwhose 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.
  
 ===== Proposal ===== ===== 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 [[https://3v4l.org/BoF4U|this example]]. Specifically, the following members are proposed to be modified:+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:
  
   * ''Throwable::getCode(): mixed;''   * ''Throwable::getCode(): mixed;''
Line 25: Line 31:
  
 ===== Proposed PHP Version(s) ===== ===== Proposed PHP Version(s) =====
-Next minor version, currently 7.2.+7.2
  
-===== Future Scope ===== +===== Voting =====
-Will come in handy when PHP will support structures like ''Enum''s, ''EnumSet''s, etc.+
  
-===== Proposed Voting Choices ===== +2/3 majority is required. Voting will end on 27th of Jan. 
-Accept "Throwable error code's type generalization"Requires 50% + 1 majority.+ 
 +<doodle title="Accept Throwables error code generalization?" auth="WesNetmo" voteType="single" closed="true"> 
 +   * Yes 
 +   * No 
 +</doodle>
  
 ===== Patches and Tests ===== ===== Patches and Tests =====
Line 37: Line 46:
  
 ===== References ===== ===== References =====
-N/A+[[http://externals.io/thread/573|Discussion on externals.io]]
rfc/throwable-code-generalization.1482052911.txt.gz · Last modified: 2017/09/22 13:28 (external edit)