rfc:intersection_types
Differences
This shows you the differences between two versions of the page.
Next revision | Previous revisionNext revisionBoth sides next revision | ||
rfc:intersection_types [2016/04/27 17:23] – created levim | rfc:intersection_types [2016/04/28 03:55] – levim | ||
---|---|---|---|
Line 3: | Line 3: | ||
* Date: 2016-04-27 | * Date: 2016-04-27 | ||
* Author: Levi Morrison < | * Author: Levi Morrison < | ||
- | * Status: | + | * Status: |
* First Published at: http:// | * First Published at: http:// | ||
Line 27: | Line 27: | ||
} | } | ||
} | } | ||
+ | |||
+ | // Fatal error: Uncaught TypeError: Argument 1 passed to RecordsToList() must be Countable and Traversable, | ||
+ | echo RecordsToList([" | ||
+ | |||
+ | // Fine: | ||
+ | echo RecordsToList(new ArrayObject([" | ||
+ | // Output: | ||
+ | // <ol> | ||
+ | // < | ||
+ | // < | ||
+ | // < | ||
+ | // < | ||
+ | // </ol> | ||
+ | |||
</ | </ | ||
+ | |||
+ | Note that if [[rfc: | ||
+ | <PHP> | ||
+ | function RecordsToList(Array | (Countable & Traversable) $input): String { | ||
+ | if (count($input) > 0) { | ||
+ | $output = "< | ||
+ | foreach ($input as $value) { | ||
+ | $output .= " | ||
+ | } | ||
+ | $output .= "</ | ||
+ | return $output; | ||
+ | } else { | ||
+ | return "< | ||
+ | } | ||
+ | } | ||
+ | </ | ||
+ | |||
+ | When union and intersection types are in the same expression they must be grouped with parenthesis (demonstrated above). The following is invalid: | ||
+ | |||
+ | <PHP> | ||
+ | function RecordsToList(Array | Countable & Traversable): | ||
+ | // ... | ||
+ | } | ||
+ | </ | ||
+ | |||
===== Backward Incompatible Changes ===== | ===== Backward Incompatible Changes ===== | ||
Line 47: | Line 86: | ||
===== References ===== | ===== References ===== | ||
- | Original announcement on Mailing List of rationale for this feature: http:// | + | * Original announcement on Mailing List of rationale for this feature: http:// |
+ | * Announcement for discussion phase: http:// | ||
rfc/intersection_types.txt · Last modified: 2017/09/22 13:28 by 127.0.0.1