rfc:scalar_type_hints_v5
Differences
This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
rfc:scalar_type_hints_v5 [2015/02/19 16:48] – spelling ircmaxell | rfc:scalar_type_hints_v5 [2018/10/17 11:38] (current) – Fix table align in "bool" column carusogabriel | ||
---|---|---|---|
Line 1: | Line 1: | ||
====== PHP RFC: Scalar Type Declarations ====== | ====== PHP RFC: Scalar Type Declarations ====== | ||
- | * Version: 0.5.1 | + | * Version: 0.5.3 |
* Date: 2015-02-18 | * Date: 2015-02-18 | ||
* Author: Anthony Ferrara < | * Author: Anthony Ferrara < | ||
- | * Status: | + | * Status: |
* First Published at: http:// | * First Published at: http:// | ||
* Forked From: http:// | * Forked From: http:// | ||
Line 125: | Line 125: | ||
The table shows which types are accepted and converted for scalar type declarations. '' | The table shows which types are accepted and converted for scalar type declarations. '' | ||
- | ^ Type declaration | + | ^ Type declaration |
- | ^ '' | + | ^ '' |
- | ^ '' | + | ^ '' |
- | ^ '' | + | ^ '' |
- | ^ '' | + | ^ '' |
< | < | ||
Line 145: | Line 145: | ||
These strict type checking rules are used for userland scalar type declarations, | These strict type checking rules are used for userland scalar type declarations, | ||
- | The one exception is that [[http:// | + | The one exception is that [[http:// |
<file php widening.php> | <file php widening.php> | ||
Line 159: | Line 159: | ||
In this case, we're passing an '' | In this case, we're passing an '' | ||
+ | |||
+ | 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(" | ||
+ | ?> | ||
+ | </ | ||
+ | |||
+ | This would defeat the purpose of strict typing. | ||
+ | |||
+ | Therefore, this RFC proposes to bypass function execution in strict mode if there' | ||
+ | |||
===== Example ===== | ===== Example ===== | ||
Line 378: | Line 403: | ||
In line with [[http:// | In line with [[http:// | ||
- | It however also means that narrowing conversions (float-> | + | It however also means that narrowing conversions (float-> |
+ | |||
+ | Note: If you read the Java spec, you'll notice that it does mention narrowing conversions. It only allows them in assignment or explicit casts however. So they do not apply in the case this proposal puts forward. | ||
==== Weak Should Error On "10 Birds" Style-Strings Passed To Int Parameters ==== | ==== Weak Should Error On "10 Birds" Style-Strings Passed To Int Parameters ==== | ||
Line 564: | Line 591: | ||
Allowing strict " | Allowing strict " | ||
- | Therefore, this proposal explicitly disallows changing the type mode anywhere within the file except the first line. Since the first line is the only allowed type change, block mode does not make sense (as there could only ever be a single block in the file). | + | Therefore, this proposal explicitly disallows changing the type mode anywhere within the file except the first line. Since the first line is the only allowed type change, block mode does not make sense (as there could only ever be a single block in the file). |
+ | |||
+ | Additionally, | ||
==== Internal Functions Do Not Have Declared Return Types ==== | ==== Internal Functions Do Not Have Declared Return Types ==== | ||
Line 611: | Line 640: | ||
=== Current Position === | === Current Position === | ||
+ | https:// | ||
This is not a two-part proposal. The proposal is of a unified system that was designed to work together. As such, neither part (weak-only or strict-only) is designed to stand on its own without the other part. | This is not a two-part proposal. The proposal is of a unified system that was designed to work together. As such, neither part (weak-only or strict-only) is designed to stand on its own without the other part. | ||
Line 651: | Line 680: | ||
===== Proposed PHP Version(s) ===== | ===== Proposed PHP Version(s) ===== | ||
- | This is proposed for the next PHP x, currently PHP 7. The acceptance for said version will depend on timing | + | This proposal targets |
===== RFC Impact ===== | ===== RFC Impact ===== | ||
Line 674: | 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=" | ||
+ | * Yes | ||
+ | * No | ||
+ | </ | ||
+ | |||
+ | 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 ===== | ||
Line 695: | Line 731: | ||
===== Changelog ===== | ===== Changelog ===== | ||
+ | * v0.5.3 Change version target back and add line about bypassing function execution on type error in strict mode | ||
+ | * v0.5.2 Change version target | ||
* v0.5.1 Remove aliases from proposal | * v0.5.1 Remove aliases from proposal | ||
* v0.5 Fork from Andrea' | * v0.5 Fork from Andrea' |
rfc/scalar_type_hints_v5.txt · Last modified: 2018/10/17 11:38 by carusogabriel