rfc:prototypecasting
Differences
This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
rfc:prototypecasting [2012/02/27 23:51] – [Implementation] davey | rfc:prototypecasting [2017/09/22 13:28] (current) – external edit 127.0.0.1 | ||
---|---|---|---|
Line 1: | Line 1: | ||
- | ====== | + | ====== |
* Version: 0.1 | * Version: 0.1 | ||
* Date: 2012-02-27 | * Date: 2012-02-27 | ||
Line 9: | Line 9: | ||
===== Introduction ===== | ===== Introduction ===== | ||
- | There has been much discussion about adding type-hinting for scalar values; with the largest hurdle being that "it isn't the PHP way", especially with regard to " | + | **This proposal |
With both data input from a user both via HTTP and CLI coming in as strings, we very commonly compare and type juggle strings to ints, floats and booleans with little (and well known) repercussions. | With both data input from a user both via HTTP and CLI coming in as strings, we very commonly compare and type juggle strings to ints, floats and booleans with little (and well known) repercussions. | ||
This RFC proposes the idea of specifying how arguments will be type cast, and automatically type casting them upon input into functions. | This RFC proposes the idea of specifying how arguments will be type cast, and automatically type casting them upon input into functions. | ||
- | |||
====== Prototype Argument Type Casting ======= | ====== Prototype Argument Type Casting ======= | ||
Line 20: | Line 19: | ||
<code php> | <code php> | ||
<?php | <?php | ||
- | function addProfile( (string) $username, (int) $age, (float) $salary) { | + | function addProfile( (string) $name, (int) $age, (float) $heightInMeters) { |
+ | echo gettype($name); | ||
+ | echo gettype($age); | ||
+ | echo gettype($heightInMeters); | ||
+ | } | ||
- | } | + | addProfile(" |
?> | ?> | ||
</ | </ | ||
Line 32: | Line 35: | ||
===== Implementation ===== | ===== Implementation ===== | ||
- | * The choice of syntax | + | * The choice of syntax: |
- | * The most important is developer | + | * Developer |
- | * The second is that it removes any ambiguity about it' | + | * Removes |
- | * All type-casting should work exactly as it does when using the casting operators normally (e.g. '' | + | * All type-casting should work exactly as it does when using the casting operators normally (e.g. '' |
* The user is informed just by looking at the prototype what the function is expecting, and more importantly how it will be cast | * The user is informed just by looking at the prototype what the function is expecting, and more importantly how it will be cast | ||
* The user should **never** be penalized (with a notice/ | * The user should **never** be penalized (with a notice/ |
rfc/prototypecasting.1330386665.txt.gz · Last modified: 2017/09/22 13:28 (external edit)