rfc:typecheckingweak
Differences
This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revision | Next revisionBoth sides next revision | ||
rfc:typecheckingweak [2009/07/12 08:28] – Initial work zeev | rfc:typecheckingweak [2009/07/12 09:37] – More initial work (conversion logic) zeev | ||
---|---|---|---|
Line 27: | Line 27: | ||
- | ===== Suggested | + | ===== Proposed |
Conceptually, | Conceptually, | ||
+ | <code php> | ||
function foo(int x) {} | function foo(int x) {} | ||
function bar(x, y, float z) {} | function bar(x, y, float z) {} | ||
function baz(int x, float y, string z) {} | function baz(int x, float y, string z) {} | ||
+ | function foobar(int &x) {} | ||
+ | </ | ||
Once a function argument has been designated a scalar type hint - the function author is completely relieved of any further checks and conversions, | Once a function argument has been designated a scalar type hint - the function author is completely relieved of any further checks and conversions, | ||
Line 40: | Line 43: | ||
- Does the value to-be-passed have the type required by the function code? If so, pass it on as-is. | - Does the value to-be-passed have the type required by the function code? If so, pass it on as-is. | ||
- | - Can the value be converted to the type required by the function (as per the conversion table below)? | + | - Can the value be converted to the type required by the function (as per the Conversion Logic below)? |
- Emit an error or throw an exception. | - Emit an error or throw an exception. | ||
+ | **Note: | ||
+ | ===== Conversion Logic ===== | ||
+ | |||
+ | ^ value ^ string | ||
+ | ^ true (boolean) | ||
+ | ^ false (boolean) | ||
+ | ^ 0 (integer) | ||
+ | ^ 1 (integer) | ||
+ | ^ 12 (integer) | ||
+ | ^ 12.0 (double) | ||
+ | ^ 12.34 (double) | ||
+ | ^ ' | ||
+ | ^ ' | ||
+ | ^ ' | ||
+ | ^ ' | ||
+ | ^ ' | ||
+ | ^ ' | ||
+ | ^ ' | ||
+ | ^ ' | ||
+ | ^ ' | ||
+ | ^ empty string (TBD) | // | ||
+ | ^ array () (array) | ||
+ | ^ array (0 => 12) (array) | // | ||
+ | ^ NULL (NULL) | ||
+ | |||
+ | |||
+ | // | ||
+ | |||
+ | //as-is// - designates that the value is passed as-is, without conversion | ||
rfc/typecheckingweak.txt · Last modified: 2017/09/22 13:28 by 127.0.0.1