rfc:scalar-pseudo-type

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:scalar-pseudo-type [2017/12/24 17:29] – Added more Examples fleshgrinderrfc:scalar-pseudo-type [2017/12/24 23:33] (current) – Added object to the analogous list of other types fleshgrinder
Line 10: Line 10:
  
 ===== Proposal ===== ===== Proposal =====
-This RFC proposes a new ''scalar'' pseudo-type. This type is analogous to ''callable'' and ''iterable'', accepting multiple types instead of one single type.+This RFC proposes a new ''scalar'' pseudo-type. This type is analogous to ''callable''''iterable'', and ''object'', accepting multiple types instead of one single type.
  
 ''scalar'' accepts ''bool'', ''float'', ''int'', and ''string''. All of these types can be safely coerced to a ''string'' and be printed. ''scalar'' accepts ''bool'', ''float'', ''int'', and ''string''. All of these types can be safely coerced to a ''string'' and be printed.
Line 81: Line 81:
  
 The function [[https://php.net/is-scalar|is_scalar]] to determine whether a value is ''scalar'' or not already exist in PHP since a long time and must not be added. The function [[https://php.net/is-scalar|is_scalar]] to determine whether a value is ''scalar'' or not already exist in PHP since a long time and must not be added.
 +
 +====== Weak Mode ======
 +Objects with a magic ''toString'' method are accepted and treated as strings in weak mode. The behavior is 1:1 the same as if the type constraint would have been ''string'' in the first place for objects. This ensures perfect consistency and adheres to the principle of least astonishment.
  
 ====== Examples ====== ====== Examples ======
Line 154: Line 157:
 ===== Backward Incompatible Changes ===== ===== Backward Incompatible Changes =====
 ''scalar'' is implemented as reserved name, therefore a class, interface, or trait named ''scalar'' cannot be declared.  ''scalar'' is implemented as reserved name, therefore a class, interface, or trait named ''scalar'' cannot be declared. 
- 
-===== Open Issues ===== 
-  * Whether ''scalar'' should accept objects with a magic ''toString'' method in weak mode like the ''string'' constraint does. 
  
 ===== Proposed PHP Version(s) ===== ===== Proposed PHP Version(s) =====
rfc/scalar-pseudo-type.1514136547.txt.gz · Last modified: 2017/12/24 17:29 by fleshgrinder