rfc:object-typehint
Differences
This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
rfc:object-typehint [2016/11/14 09:56] – brzuchal | rfc:object-typehint [2017/09/22 13:28] (current) – external edit 127.0.0.1 | ||
---|---|---|---|
Line 1: | Line 1: | ||
====== PHP RFC: Object typehint ====== | ====== PHP RFC: Object typehint ====== | ||
- | * Version: | + | * Version: |
* Date: 2016-08-12 | * Date: 2016-08-12 | ||
* Author: Michał Brzuchalski < | * Author: Michał Brzuchalski < | ||
- | * Status: | + | * Status: |
* First Published at: https:// | * First Published at: https:// | ||
Line 20: | Line 20: | ||
As it would be used internally, object would become a reserved classname, unavailable for use as a class name in userland code. | As it would be used internally, object would become a reserved classname, unavailable for use as a class name in userland code. | ||
- | For class methods that use object as either a parameter or return type. | + | For class methods that use object as either a parameter or return type, the inheritance checks would use contravariance for parameter types, and covariance for return types. |
===== Examples ===== | ===== Examples ===== | ||
Line 112: | Line 113: | ||
switch ($type) { | switch ($type) { | ||
case ' | case ' | ||
- | case ' | + | case ' |
case ' | case ' | ||
} | } | ||
Line 188: | Line 189: | ||
=== Argument typehint contravariance === | === Argument typehint contravariance === | ||
- | + | Classes | |
- | Classes | + | |
- | This behavior is the similar as that proposed for ' | + | |
<code php> | <code php> | ||
Line 209: | Line 208: | ||
</ | </ | ||
- | In above example ' | + | This is normally known as [[https:// |
+ | |||
+ | Classes extending/ | ||
+ | |||
+ | <code php> | ||
+ | class Foo { | ||
+ | } | ||
+ | |||
+ | class Bar { | ||
+ | public function foo(object $object) : object { | ||
+ | return $object; | ||
+ | } | ||
+ | } | ||
+ | |||
+ | class Baz extends Bar { | ||
+ | public function foo(Foo $object) : object { | ||
+ | return $object; | ||
+ | } | ||
+ | } | ||
+ | </ | ||
+ | |||
+ | In this situation the standard PHP warning for incompatible signatures will be raised. | ||
+ | |||
+ | <code php> | ||
+ | Declaration of Baz:: | ||
+ | </ | ||
=== Return type covariance === | === Return type covariance === | ||
Classes extending/ | Classes extending/ | ||
- | This behavior is the similar as that proposed for ' | + | This behavior is the similar as that proposed for ' |
<code php> | <code php> | ||
Line 244: | Line 268: | ||
===== Backward Incompatible Changes ===== | ===== Backward Incompatible Changes ===== | ||
- | Althought | + | Although 'object' |
===== Proposed PHP Version(s) ===== | ===== Proposed PHP Version(s) ===== | ||
Line 262: | Line 286: | ||
===== Proposed Voting Choices ===== | ===== Proposed Voting Choices ===== | ||
- | As this is a language change, a 2/3 majority is required. The vote is a straight Yes/No vote for accepting the RFC and merging the patch. | + | Voting will run from 2017-05-17, for two weeks, until 2017-05-31. |
+ | As this is a language change, a 2/3 majority is required. | ||
+ | The vote is a straight Yes/No vote for accepting the RFC and merging the patch. | ||
+ | The additional vote is also a straight Yes/No vote for accepting variance behaviour on the object type. | ||
- | <doodle title=" | + | <doodle title=" |
+ | * Yes | ||
+ | * No | ||
+ | </ | ||
+ | |||
+ | <doodle title=" | ||
* Yes | * Yes | ||
* No | * No | ||
Line 271: | Line 303: | ||
===== Patches and Tests ===== | ===== Patches and Tests ===== | ||
* PR[[https:// | * PR[[https:// | ||
+ | * Online Runtime Execution at [[https:// | ||
+ | |||
+ | ===== Discussions ===== | ||
+ | |||
+ | * [[https:// | ||
+ | * [[https:// | ||
+ |
rfc/object-typehint.1479117366.txt.gz · Last modified: 2017/09/22 13:28 (external edit)