rfc:prototypecasting

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:prototypecasting [2012/02/27 23:52] – [Implementation] daveyrfc:prototypecasting [2017/09/22 13:28] (current) – external edit 127.0.0.1
Line 1: Line 1:
-====== Request for Comments: Prototype Argument Type Casting ======+====== RFC: Prototype Argument Type Casting ======
   * 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 "punishing" the consumers of libraries by putting the onus of type-casting onto the them. This proposal intends to provide an alternative to type-hinting.+**This proposal is in no way related to scalar type-hinting.**
  
 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);   // "string" 
 +    echo gettype($age);    // "integer" 
 +    echo gettype($heightInMeters); // "double" 
 +}
  
-}+addProfile("Davey Shafik", "27", "1.77");
 ?> ?>
 </code> </code>
rfc/prototypecasting.1330386728.txt.gz · Last modified: 2017/09/22 13:28 (external edit)