rfc:typehint

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
Next revisionBoth sides next revision
rfc:typehint [2008/04/09 02:36] feliperfc:typehint [2008/04/17 14:36] felipe
Line 3: Line 3:
   * Date: 2008-04-07   * Date: 2008-04-07
   * Author: Felipe Pena <felipensp@gmail.com>   * Author: Felipe Pena <felipensp@gmail.com>
-  * Status: Under Discussion+  * Status: [[http://news.php.net/php.internals/37049|Under Discussion]]
  
 +====== Details of implementation ======
 +**Parameter type hint:**
 +  - The behavior when the default parameter value is ''NULL'' was keeped.
 +**Both:**
 +  - Binary and unicode string are specified by ''string''.
  
-===== BC Break =====+===== Return value type hint =====
  
-=== Parameter type hint ===+==== BC Break ==== 
 +No BC break using the "(type)" syntax. (Inspirated by Objective-C)
  
-== New tokens (new keywords) == 
-  - T_INTEGER (Keywords: int, integer) 
-  - T_BOOLEAN (Keywords: bool, boolean) 
-  - T_DOUBLE (Keywords: real, float, double) 
-  - T_OBJECT (Keyword: object) 
-  - T_RESOURCE (Keyword: resource) 
-  - T_STR (Keyword: string) 
  
-===== Return value type hint - Examples =====+==== Examples ====
  
 === Using inside namespaces === === Using inside namespaces ===
Line 98: Line 97:
 } }
  
-test('1337'); +test('1337'); // Catchable fatal error: The returned value must be of the type integer
-test(-1); +
-test(1); +
-test(1.); // Catchable fatal error: The returned value must be of the type integer+
 </code> </code>
  
-===== Parameter type hint - Examples =====+ 
 +===== Parameter type hint ===== 
 + 
 +==== BC Break ==== 
 + 
 +== New tokens (new keywords) == 
 +  T_INTEGER (Keywords: int, integer) 
 +  - T_BOOLEAN (Keywords: bool, boolean) 
 +  - T_DOUBLE (Keywords: real, float, double) 
 +  - T_OBJECT (Keyword: object) 
 +  - T_RESOURCE (Keyword: resource) 
 +  - T_STR (Keyword: string) 
 + 
 +==== Other changes ==== 
 +  - Removed ZEND_ARG_ARRAY_INFO() 
 +  - Added ZEND_ARG_PHP_TYPE_INFO() 
 +<code diff u> 
 +-#define ZEND_ARG_ARRAY_INFO(pass_by_ref, name, allow_null) { {#name}, sizeof(#name)-1, {NULL}, 0, 1, allow_null, pass_by_ref, 0, 0 }, 
 ++#define ZEND_ARG_PHP_TYPE_INFO(pass_by_ref, name, php_type, allow_null) { {#name}, sizeof(#name)-1, {NULL}, 0, php_type, allow_null, pass_by_ref, 0, 0 }, 
 +</code> 
 +  - **Reflection**: ReflectionParameter class: 
 +    - Added: 
 +      - isInt() 
 +      - isDouble() 
 +      - isBool() 
 +      - isString() 
 +      - isObject() 
 +      - isResource() 
 + 
 + 
 +==== Examples ====
  
 === integer / int === === integer / int ===
Line 114: Line 140:
 test("1337"); test("1337");
 test(-1); test(-1);
-test("1."); // Catchable fatal error: Argument 1 passed to test() must be an integer, string given+test("1."); // Catchable fatal error: Argument 1 passed to test() must be of the type integer, string given
  
 function test(integer $value = '1') { function test(integer $value = '1') {
Line 129: Line 155:
 test(.1); test(.1);
 test("1."); test("1.");
-test("1337"); // Catchable fatal error: Argument 1 passed to test() must be an double, string given+test("1337"); // Catchable fatal error: Argument 1 passed to test() must be of the type double, string given
  
 function test(double $value = '1') { function test(double $value = '1') {
Line 147: Line 173:
 test('1'); test('1');
 test(''); test('');
-test(null); // Catchable fatal error: Argument 1 passed to test() must be an boolean, null given+test(null); // Catchable fatal error: Argument 1 passed to test() must be of the type boolean, null given
 </code> </code>
  
Line 156: Line 182:
  
 test(fopen(__FILE__, 'r')); test(fopen(__FILE__, 'r'));
-test(NULL); // Catchable fatal error: Argument 1 passed to test() must be an resource, null given+test(NULL); // Catchable fatal error: Argument 1 passed to test() must be of the type resource, null given
 </code> </code>
  
Line 165: Line 191:
  
 test(new stdclass); test(new stdclass);
-test(NULL); // Catchable fatal error: Argument 1 passed to test() must be an object, null given+test(NULL); // Catchable fatal error: Argument 1 passed to test() must be of the type object, null given
  
 function test(object $value = 1) { function test(object $value = 1) {
Line 174: Line 200:
  
  
-===== Patches =====+===== Patches & tests =====
  
-  - Return value type hint: http://felipe.ath.cx/diff/return_type_hint.diff (under construction) +  - Return value type hint: http://felipe.ath.cx/diff/return_type_hint.diff 
-  - Parameter type hint: http://felipe.ath.cx/diff/param_type_hint.diff (under construction)+  - Parameter type hint: http://felipe.ath.cx/diff/param_type_hint.diff 
 +  - Tests: http://felipe.ath.cx/diff/tests/
  
rfc/typehint.txt · Last modified: 2017/09/22 13:28 by 127.0.0.1