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/24 20:58] – [Changelog] 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 28: Line 28:
 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.
  
-** Update: allowing NULL to be unconditionally returned has been removed for the current discussion. With the current patch, if you declare a return type, you must return that. **+=== 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 61: Line 63:
     {     {
         return 'strlen';         return 'strlen';
 +    }
 +    
 +    // The nullable keyword allows you to return null 
 +    protected nullable ArrayObject getArrayObject()
 +    {
 +        return null;
     }     }
          
Line 161: 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 172: 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 +
- +
-Patch with nullable token: http://www.willfitch.com/php/nullable.patch +
- +
-Github: https://github.com/fitchwh/php-src (returntype branch)+
  
  
Line 188: Line 190:
   - Updated to remove allowing NULL to be returned unconditionally when declaring return types   - 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   - 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.1324760306.txt.gz · Last modified: 2017/09/22 13:28 (external edit)