rfc:returntypehint2

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:returntypehint2 [2011/12/21 22:23] – [Functional Implementation] fitchwhrfc:returntypehint2 [2017/09/22 13:28] (current) – external edit 127.0.0.1
Line 3: Line 3:
   * Date: 2011-12-13   * Date: 2011-12-13
   * Author: Will Fitch <will.fitch@gmail.com>   * Author: Will Fitch <will.fitch@gmail.com>
-  * Status: Under Discussion+  * Status: Withdrawn
  
  
Line 27: Line 27:
  
 This implementation of return type hinting follows the same approach.  This provides consistency that developers appreciate.  When and if type hinting allows for additional types, the change can be applied to both methods and parameters. This implementation of return type hinting follows the same approach.  This provides consistency that developers appreciate.  When and if type hinting allows for additional types, the change can be applied to both methods and parameters.
 +
 +=== Returning NULL ===
 +
 +By default, if you specify a return type hint, you **must** return that type.  However, a new keyword "nullable" has been added to bypass this requirement.  Much like the parameter type hinting, this provides developers with added flexibility, and allows developers using an API to easily identify and code for that situation.
  
 === Example Implementations === === Example Implementations ===
Line 56: Line 60:
     }     }
          
-    public array getNullValue()+    public callable getCallableString() 
 +    { 
 +        return 'strlen'; 
 +    } 
 +     
 +    // The nullable keyword allows you to return null  
 +    protected nullable ArrayObject getArrayObject()
     {     {
         return null;         return null;
     }     }
          
-    public callable getCallableString()+    private callable methodModsDontMatter()
     {     {
-        return 'strlen';+        return 'str_replace'
 +    } 
 +     
 +    ArrayObject methodsDontNeedModsActually() 
 +    { 
 +        return new ArrayObject();
     }     }
 } }
Line 154: Line 169:
 === Tests === === Tests ===
  
-A total of 22 tests were added to tests/classes/ All tests file names are prefixed with "method_returntype_" for easy identification.  The tests do the following:+A total of 21 tests were added to tests/classes/ All tests file names are prefixed with "method_returntype_" for easy identification.  The tests do the following:
  
   * Determine that non-namespaced and namespaced class name don't produce a syntax error   * Determine that non-namespaced and namespaced class name don't produce a syntax error
Line 165: Line 180:
 ===== Patch ===== ===== Patch =====
  
-The downloadable patch below can be applied against PHP HEADAlternatively, I keep clone a of PHP in my own GitHub sandbox.  I have provided the link to it below.  Please take note of the branch name to see the right code. +The patch for this is now outdated and gone
- +
-Patch: http://www.willfitch.com/php/returntype.patch +
- +
-Github: https://github.com/fitchwh/php-src (returntype branch)+
  
  
Line 176: Line 187:
 ===== Changelog ===== ===== Changelog =====
  
 +  - Updated to include "callable" as an accepted return type. Includes patch and documentation changes 
 +  - Updated to remove allowing NULL to be returned unconditionally when declaring return types 
 +  - Added a new patch which includes a "nullable" token for declaring a method may return null 
 +  - Updated the RFC to take "nullable" into account and replaced the old patch with the new functionality
  
rfc/returntypehint2.1324506234.txt.gz · Last modified: 2017/09/22 13:28 (external edit)