rfc:typecheckingstrictonly

Differences

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

Link to this comparison view

Next revision
Previous revision
rfc:typecheckingstrictonly [2009/07/03 20:45] – Simple placeholder pbiggarrfc:typecheckingstrictonly [2017/09/22 13:28] (current) – external edit 127.0.0.1
Line 1: Line 1:
-====== Request for Comments: How to write RFCs ====== +====== Request for Comments: Optional Strict Type Checking for Scalars ====== 
-  * Version:  +  * Version: 1.0 
-  * Date:  +  * Date: October 22, 2009 
-  * Author:  +  * Author: Ilia Alshanetsky 
-  * Status: Under Discussion+  * Status: Previously Implemented
   * First Published at: http://wiki.php.net/rfc/typecheckingstrictonly   * First Published at: http://wiki.php.net/rfc/typecheckingstrictonly
  
 +The idea is that certain applications and/or use cases could benefit from the ability to specify the specific types that functions and methods accept as parameters. The benefits of this approach is the improved code clarity and more detailed code interrogation via reflection for the purposes of WSDL and automatic comment generation. There are also security benefits of effectively being able to perform strict type checking around input parameters.
  
-A placeholder for Ilia's proposal, available from:+The patch is available here: http://ilia.ws/patch/type_hint_final.txt (for PHP 5.3) 
 +The test cases around the functionality are available here: http://ilia.ws/patch/type_hint_tests.tar.bz2
  
-http://news.php.net/php.internals/44573+The implemented functionality does "strict" type hinting, which means that if a function is declaring the parameter needing to be an integer, only an integer will be accepted, a floating point number, a string containing a number or a boolean will be rejected, resulting in an error message.
  
 +The supported type hints are as follows: (int/integer/long, float/double, string/binary, bool/boolean, resource, object)
  
 +The "object" type-hint indicates that the function and/or method is looking for an object of some-sort, rather then a specific instance of an object as the current functionality offers.
  
 +The patch also introduces additional methods into reflection, to simplify interrogation of the code.
 +
 +ReflectionParameter::isInt() - Returns whether parameter MUST be a long
 +
 +ReflectionParameter::isDouble() -Returns whether parameter MUST be a double
 +
 +ReflectionParameter::isBool() - Returns whether parameter MUST be a boolean
 +
 +ReflectionParameter::isObject() - Returns whether parameter MUST be a boolean
 +
 +ReflectionParameter::isString() - Returns whether parameter MUST be a string
 +
 +ReflectionParameter::isResource() - Returns whether parameter MUST be a resource
 +
 +ReflectionParameter::getTypeHint() - Returns what type hint is defined for this parameter
rfc/typecheckingstrictonly.1246653930.txt.gz · Last modified: 2017/09/22 13:28 (external edit)