rfc:never_for_parameter_types
Differences
This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
rfc:never_for_parameter_types [2021/08/14 14:49] – fixing typo in section title jordanrl | rfc:never_for_parameter_types [2021/08/24 11:53] (current) – Withdrawing jordanrl | ||
---|---|---|---|
Line 1: | Line 1: | ||
====== PHP RFC: Never For Parameter Types ====== | ====== PHP RFC: Never For Parameter Types ====== | ||
- | * Version: 0.1 | + | * Version: 0.2 |
* Date: 2021-08-14 | * Date: 2021-08-14 | ||
* Author: Jordan LeDoux, jordan.ledoux@gmail.com | * Author: Jordan LeDoux, jordan.ledoux@gmail.com | ||
- | * Status: | + | * Status: |
* First Published at: http:// | * First Published at: http:// | ||
===== Introduction ===== | ===== Introduction ===== | ||
- | Arguments | + | Parameters |
<code php> | <code php> | ||
Line 27: | Line 27: | ||
</ | </ | ||
- | Thus, the more specific a type is for an argument | + | Thus, the more specific a type is for an parameter |
- | Since '' | + | Since '' |
===== Use Cases ===== | ===== Use Cases ===== | ||
==== Interfaces and Abstracts ==== | ==== Interfaces and Abstracts ==== | ||
- | With the '' | + | With the '' |
<code php> | <code php> | ||
Line 46: | Line 46: | ||
</ | </ | ||
- | Implementers of the '' | + | Implementers of the '' |
- | In this way, allowing the never type for interfaces and abstracts could be a method of providing minimal support for generics while avoiding the challenges that providing generics represents. It would also not prevent or make it more difficult to provide full generics in the future. | + | In this way, allowing the never type for interfaces and abstracts could be a method of providing minimal |
Using never as a minimal form of generics in this way would require additional work, such as docblock information, | Using never as a minimal form of generics in this way would require additional work, such as docblock information, | ||
Line 54: | Line 54: | ||
==== Internal Classes and Interfaces ==== | ==== Internal Classes and Interfaces ==== | ||
Providing internal interfaces that require a type but do not specify which type can be very beneficial. This has been encountered recently with attempts to update '' | Providing internal interfaces that require a type but do not specify which type can be very beneficial. This has been encountered recently with attempts to update '' | ||
+ | |||
+ | <code php> | ||
+ | interface ArrayAccess { | ||
+ | |||
+ | public function offsetExists(never $offset): bool; | ||
+ | |||
+ | public function offsetGet(never $offset): mixed; | ||
+ | | ||
+ | public function offsetSet(never $offset, never $value): void; | ||
+ | | ||
+ | public function offsetUnset(never $offset): void; | ||
+ | |||
+ | } | ||
+ | </ | ||
Currently, internally provided interfaces that must provide flexible parameters for implementers specify the parameter as mixed, however as mixed is the top type in PHP it cannot be narrowed at all, and any code which implements the interface can not fully utilize the type system in place in PHP. | Currently, internally provided interfaces that must provide flexible parameters for implementers specify the parameter as mixed, however as mixed is the top type in PHP it cannot be narrowed at all, and any code which implements the interface can not fully utilize the type system in place in PHP. | ||
Line 77: | Line 91: | ||
Allow the use of '' | Allow the use of '' | ||
- | * '' | + | * '' |
* Attempting to call code directly that uses the '' | * Attempting to call code directly that uses the '' | ||
- | * Omitting a type to imply '' | ||
This means that an interface or class could allow implementers and subclasses to declare a type for an argument without restricting that type to anything particular. | This means that an interface or class could allow implementers and subclasses to declare a type for an argument without restricting that type to anything particular. | ||
Line 87: | Line 100: | ||
===== Proposed PHP Version(s) ===== | ===== Proposed PHP Version(s) ===== | ||
- | This change is proposed for next PHP 8.x | + | This change is proposed for PHP 8.2 |
===== RFC Impact ===== | ===== RFC Impact ===== | ||
Line 125: | Line 138: | ||
===== References ===== | ===== References ===== | ||
- | * https:// | + | * https:// |
* https:// | * https:// | ||
* https:// | * https:// | ||
* https:// | * https:// | ||
+ | * https:// | ||
+ | |||
+ | ===== Changelog ===== | ||
+ | |||
+ | * 0.1: Initial Proposal | ||
+ | * 0.2: Removed explicit widening |
rfc/never_for_parameter_types.txt · Last modified: 2021/08/24 11:53 by jordanrl