rfc:scalar_type_hints_v5

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:scalar_type_hints_v5 [2015/02/21 15:30] – Change version target back and add line about bypassing function execution on type error in strict mode ircmaxellrfc:scalar_type_hints_v5 [2018/10/17 11:38] (current) – Fix table align in "bool" column carusogabriel
Line 3: Line 3:
   * Date: 2015-02-18   * Date: 2015-02-18
   * Author: Anthony Ferrara <ircmaxell@php.net> (original Andrea Faulds, ajf@ajf.me)   * Author: Anthony Ferrara <ircmaxell@php.net> (original Andrea Faulds, ajf@ajf.me)
-  * Status: Discussion+  * Status: Implemented
   * First Published at: http://wiki.php.net/rfc/scalar_type_hints_v5   * First Published at: http://wiki.php.net/rfc/scalar_type_hints_v5
   * Forked From: http://wiki.php.net/rfc/scalar_type_hints   * Forked From: http://wiki.php.net/rfc/scalar_type_hints
Line 125: Line 125:
 The table shows which types are accepted and converted for scalar type declarations. ''NULL'', arrays and resources are never accepted for scalar type declarations, and so are not included in the table. The table shows which types are accepted and converted for scalar type declarations. ''NULL'', arrays and resources are never accepted for scalar type declarations, and so are not included in the table.
  
-^ Type declaration  ^ int  ^ float    ^ string   ^ bool ^ object +^ Type declaration  ^ int  ^ float    ^ string   ^ bool  ^ object 
-^ ''int''           ^ yes  ^ yes*     ^ yes†     ^ yes  ^ no      ^ +^ ''int''           ^ yes  ^ yes*     ^ yes†     ^ yes   ^ no      ^ 
-^ ''float''         ^ yes  ^ yes      ^ yes†     ^ yes  ^ no      ^ +^ ''float''         ^ yes  ^ yes      ^ yes†     ^ yes   ^ no      ^ 
-^ ''string''        ^ yes  ^ yes      ^ yes      ^ yes  ^ yes‡    ^ +^ ''string''        ^ yes  ^ yes      ^ yes      ^ yes   ^ yes‡    ^ 
-^ ''bool''          ^ yes  ^ yes      ^ yes      ^ yes  ^ no      ^+^ ''bool''          ^ yes  ^ yes      ^ yes      ^ yes   ^ no      ^
  
 <nowiki>*</nowiki>Only non-NaN floats between ''PHP_INT_MIN'' and ''PHP_INT_MAX'' accepted. (New in PHP 7, see the [[rfc:zpp_fail_on_overflow|ZPP Failure on Overflow]] RFC) <nowiki>*</nowiki>Only non-NaN floats between ''PHP_INT_MIN'' and ''PHP_INT_MAX'' accepted. (New in PHP 7, see the [[rfc:zpp_fail_on_overflow|ZPP Failure on Overflow]] RFC)
Line 161: Line 161:
  
 No other conversions are allowed. No other conversions are allowed.
 +
 +==== Error Handler Behavior In Strict Mode ====
 +
 +Currently it's possible to bypass error check failures using an error handler:
 +
 +<file php error_handler_fail.php>
 +<?php
 +declare(strict_types=1);
 +set_error_handler(function() {
 +    return true;
 +});
 +
 +function foo(int $abc) {
 +    var_dump($abc);
 +}
 +foo("test"); // string(4) "test"
 +?>
 +</file>
 +
 +This would defeat the purpose of strict typing. 
 +
 +Therefore, this RFC proposes to bypass function execution in strict mode if there's a type mismatch error (just like internal functions do today). The implementation is not complete, as this behavior would be superseded by [[rfc:engine_exceptions]] if it passed. Therefore the implementation will wait for the completion of voting on that RFC.
 +
  
 ===== Example ===== ===== Example =====
Line 250: Line 273:
 // Catchable fatal error: Return value of foobar() must be of the type integer, float returned // Catchable fatal error: Return value of foobar() must be of the type integer, float returned
 </file> </file>
- 
-==== Error Handler Behavior In Strict Mode ==== 
- 
-Currently it's possible to bypass error check failures using an error handler: 
- 
-<file php error_handler_fail.php> 
-<?php 
-declare(strict_types=1); 
-set_error_handler(function() { 
-    return true; 
-} 
-function foo(int $abc) { 
-    var_dump($abc); 
-} 
-foo("test"); // string(4) "test" 
-?> 
-</file> 
- 
-This would defeat the purpose of strict typing.  
- 
-Therefore, this RFC proposes to bypass function execution in strict mode if there's a type mismatch error (just like internal functions do today). The implementation is not complete, as this behavior would be superseded by [[rfc:engine_exceptions]] if it passed. Therefore the implementation will wait for the completion of voting on that RFC. 
  
 ===== Background and Rationale ===== ===== Background and Rationale =====
Line 701: Line 703:
  
 As this is a language change, this RFC requires a 2/3 majority to pass. As this is a language change, this RFC requires a 2/3 majority to pass.
 +
 +<doodle title="Accept Scalar Type Declarations With Optional Strict Mode?" auth="ircmaxell" voteType="single" closed="true">
 +   * Yes
 +   * No
 +</doodle>
 +
 +This vote is opened on February 26th, 2015 and will close March 16th at 21:00 UTC as announced on list.
  
 ===== Patches and Tests ===== ===== Patches and Tests =====
rfc/scalar_type_hints_v5.txt · Last modified: 2018/10/17 11:38 by carusogabriel