rfc:reflectiontypeimprovements

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:reflectiontypeimprovements [2016/06/15 15:20] levimrfc:reflectiontypeimprovements [2020/08/01 23:51] (current) – Status is "Declined" carusogabriel
Line 1: Line 1:
-====== PHP RFC: Your Title Here ======+====== PHP RFC: ReflectionType Improvements ======
   * Version: 1.0   * Version: 1.0
   * Date: 2016-06-10   * Date: 2016-06-10
   * Author: Levi Morrison <levim@php.net>   * Author: Levi Morrison <levim@php.net>
-  * Status: Draft +  * Status: Declined 
-  * First Published at: http://wiki.php.net/rfc/ReflectionTypeImprovements+  * First Published at: https://wiki.php.net/rfc/ReflectionTypeImprovements
  
 ===== Introduction ===== ===== Introduction =====
-For PHP 7.0 the ''ReflectionType'' API was introduced in conjunction with [[rfc::return_types] | return types]]. Its minimal API was intended to be the base for future improvements; this RFC are those improvements.+For PHP 7.0 the ''ReflectionType'' API was introduced in conjunction with [[rfc::return_types] | return types]]. Its minimal API was intended to be the base for future improvements; this RFC contains some of those improvements.
  
 ===== Proposal ===== ===== Proposal =====
-This RFC adds several new subtypes for ''ReflectionType''; here is their hierarchy: +This RFC adds two new subtypes for ''ReflectionType''; here are their stubs:
- +
-  * ReflectionType (already exists) +
-    * ReflectionSingularType +
-      * ReflectionIntType +
-      * ReflectionFloatType +
-      * ReflectionBoolType +
-      * ReflectionStringType +
-      * ReflectionArrayType +
-      * ReflectionCallableType +
-      * ReflectionVoidType +
-      * ReflectionClassType +
- +
-''ReflectionSingularType'' has a new method named ''getName()'' which returns the string name of the type it represents. Here is a stub the represents its API:+
  
 <PHP> <PHP>
-class ReflectionSingularType extends ReflectionType {+class ReflectionNamedType extends ReflectionType {
     public function getName(): string;     public function getName(): string;
 } }
-</PHP> 
-A call to the ''getName()'' method of a ''SingularType'' that represents any of ''int'', ''?int'' or ''int $foo = null'' will return ''int'' in each case.  
  
-''ReflectionClassType'' has an additional method ''getClass()'' that obtains the ''ReflectionClass'' of the type it represents. Here is its stub: +class ReflectionClassType extends ReflectionNamedType {
- +
-<PHP> +
-class ReflectionClassType extends ReflectionSingularType {+
     public function getClass(): ReflectionClass;     public function getClass(): ReflectionClass;
 } }
 </PHP> </PHP>
  
-The engine will return a subtype of ''ReflectionSingularType'' if possible. For builtin types the engine will return ''ReflectionIntType'', ''ReflectionFloatType'', etc as appropriate. If the engine does not recognize a type it will call the autoloader; if the class is found then a ''ReflectionClassType'' will be returned and otherwise a plain ''ReflectionSingularType'' will be returned.+If the engine does not recognize a type it will call the autoloader; if the class is found then a ''ReflectionClassType'' will be returned. Presently in all other cases a plain ''ReflectionNamedType'' will be returned but this may change in the future. For instance if we had intersection types they would be unnamed and therefore would be different subtype of ''ReflectionType''.  
 + 
 +A call to the ''getName()'' method of a ''ReflectionNamedType'' that represents any of ''int'', ''?int'' or ''int $foo = null'' will return ''int'' in each case. Note that the ''<nowiki>__toString</nowiki>'' method would return ''int'', ''?int'' and ''?int'' respectively. Note that the names of builtin types are normalized, so ''getName()'' on builtin types will always be in lower case and thus safe for string comparisons.
  
 ===== Backward Incompatible Changes ===== ===== Backward Incompatible Changes =====
Line 57: Line 41:
 It is unclear if voting requires 50%+1 or 2/3. On one hand this is not a language change but on the other this does contain a BC break. Rather than debating it one way or the other I've chosen to require 2/3. It is unclear if voting requires 50%+1 or 2/3. On one hand this is not a language change but on the other this does contain a BC break. Rather than debating it one way or the other I've chosen to require 2/3.
  
-The vote will be a simple yes or no for these changes.+The vote is a simple yes or no for these changes. Voting opened 2016-06-30 and will close 2016-07-08. 
 + 
 +<doodle title="Accept ReflectionType Improvements RFC?" auth="levim" voteType="single" closed="true"> 
 +   * Yes 
 +   * No 
 +</doodle>
  
 ===== Patches and Tests ===== ===== Patches and Tests =====
 The patch for this is not difficult; it will be coming soon. The patch for this is not difficult; it will be coming soon.
  
rfc/reflectiontypeimprovements.1466004036.txt.gz · Last modified: 2017/09/22 13:28 (external edit)