rfc:typecheckingweak

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
Next revisionBoth sides next revision
rfc:typecheckingweak [2009/07/12 13:52] – Some fixes and additions. zeevrfc:typecheckingweak [2009/07/12 15:43] – Add reference to object conversion zeev
Line 62: Line 62:
 ===== Conversion Logic ===== ===== Conversion Logic =====
  
-^ value                   ^ string       ^ float      ^ int       ^ numeric   ^ bool      +^ value                   ^ string       ^ float       ^ int        ^ numeric    ^ bool       
-^ true (boolean)          | //fail//     | 1.0        | 1         | 1         | //as-is// | +^ true (boolean)          | //fail//     | 1.0         | 1          | 1          | //as-is//  
-^ false (boolean)         | //fail//     | 0.0        | 0         | 0         | //as-is// | +^ false (boolean)         | //fail//     | 0.0         | 0          | 0          | //as-is//  
-^ 0 (integer)             | '0'          | 0.0        | //as-is// | //as-is// | false     +^ 0 (integer)             | '0'          | 0.0         | //as-is//  | //as-is//  | false      
-^ 1 (integer)             | '1'          | 1.0        | //as-is// | //as-is// | true      +^ 1 (integer)             | '1'          | 1.0         | //as-is//  | //as-is//  | true       
-^ 12 (integer)            | '12'         | 12.0       | //as-is// | //as-is// | true      +^ 12 (integer)            | '12'         | 12.0        | //as-is//  | //as-is//  | true       
-^ 12.0 (double)           | '12.0'       | //as-is//  | 12        | //as-is// | true      +^ 12.0 (double)           | '12.0'       | //as-is//   | 12         | //as-is//  | true       
-^ 12.34 (double)          | '12.34'      | //as-is//  | 12        | //as-is// | true      +^ 12.34 (double)          | '12.34'      | //as-is//   | 12         | //as-is//  | true       
-^ 'true' (string)         | //as-is//    | //fail//   | //fail//  | //fail//  | //fail//  +^ 'true' (string)         | //as-is//    | //fail//    | //fail//   | //fail//   | //fail//   
-^ 'false' (string)        | //as-is//    | //fail//   | //fail//  | //fail//  | //fail//  +^ 'false' (string)        | //as-is//    | //fail//    | //fail//   | //fail//   | //fail//   
-^ '0' (string)            | //as-is//    | 0.0        | 0         | 0         | false     +^ '0' (string)            | //as-is//    | 0.0         | 0          | 0          | false      
-^ '1' (string)            | //as-is//    | 1.0        | 1         | 1         | true      +^ '1' (string)            | //as-is//    | 1.0         | 1          | 1          | true       
-^ '12' (string)           | //as-is//    | 12.0       | 12        | 12        | true      +^ '12' (string)           | //as-is//    | 12.0        | 12         | 12         | true       
-^ '0xA' (string)          | //as-is//    | 10.0       | 10        | 10        | true      +^ '0xA' (string)          | //as-is//    | 10.0        | 10         | 10         | true       
-^ '12abc' (string)        | //as-is//    | //fail//   | //fail//  | //fail//  | //fail//  +^ '12abc' (string)        | //as-is//    | //fail//    | //fail//   | //fail//   | //fail//   
-^ '12.0' (string)         | //as-is//    | 12.0       | 12        | 12.0      | true      +^ '12.0' (string)         | //as-is//    | 12.0        | 12         | 12.0       | true       
-^ '12.34' (string)        | //as-is//    | 12.34      | 12        | 12.34     | true      +^ '12.34' (string)        | //as-is//    | 12.34       | 12         | 12.34      | true       
-^ 'foo' (string)          | //as-is//    | //fail//   | //fail//  | //fail//  | //fail//  +^ 'foo' (string)          | //as-is//    | //fail//    | //fail//   | //fail//   | //fail//   
-^ empty string (TBD)      | //as-is//    | //fail//   | //fail//  | //fail//  | //fail//  +^ empty string (TBD)      | //as-is//    | //fail//    | //fail//   | //fail//   | //fail//   
-^ array () (array)        | //fail//     | //fail//   | //fail//  | //fail//  | //fail//  +^ array () (array)        | //fail//     | //fail//    | //fail//   | //fail//   | //fail//   
-^ array (0 => 12) (array) | //fail//     | //fail//   | //fail//  | //fail//  | //fail//  +^ array (0 => 12) (array) | //fail//     | //fail//    | //fail//   | //fail//   | //fail//   
-^ NULL (NULL)             | empty string | 0.0        | 0         | 0         | false     |+^ NULL (NULL)             | empty string | 0.0         | 0          | 0          | false      | 
 +^ object                  | //fail++//   | //fail++//  | //fail++// | //fail++// | //fail++// |
  
-//fail//  - designates failureeither emitting an error or throwing an exception+//as-is//  - designates that the value is passed as-iswithout conversion
  
-//as-is// - designates that the value is passed as-iswithout conversion+//fail//   - designates failure, either emitting an error or throwing an exception 
 + 
 +//fail++// failunless a matching conversion function exists (e.g. __toString()) - in which case it will be called and used 
 + 
 + 
 +**Note:**  'scalar' and 'array' type hints remain unchanged - an array typed argument will only accept arrays, and will otherwise fail;  A scalar typed argument will accept any kind of scalar argument, but will fail on objects and arrays.
  
 In a nutshell, the conversion logic is quite similar to the one employed by internal functions, with one key difference - it is designed to fail in case of a conversion that is unlikely to 'make sense' Specifically, it breaks away from PHP's internal function behavior in two key places: In a nutshell, the conversion logic is quite similar to the one employed by internal functions, with one key difference - it is designed to fail in case of a conversion that is unlikely to 'make sense' Specifically, it breaks away from PHP's internal function behavior in two key places:
rfc/typecheckingweak.txt · Last modified: 2017/09/22 13:28 by 127.0.0.1