rfc:allow-constant-override
Differences
This shows you the differences between two versions of the page.
Next revision | Previous revision | ||
rfc:allow-constant-override [2017/03/30 22:29] – created wesnetmo | rfc:allow-constant-override [2017/09/22 13:28] (current) – external edit 127.0.0.1 | ||
---|---|---|---|
Line 1: | Line 1: | ||
- | ====== PHP RFC: Allow abstract function override ====== | + | wip |
- | + | ||
- | * Version: 0.1 | + | |
- | * Date: 2017-03-01 | + | |
- | * Author: @WesNetmo @ Twitter | + | |
- | * Status: Voting | + | |
- | * First Published at: https:// | + | |
- | + | ||
- | ===== Proposal ===== | + | |
- | + | ||
- | PHP 7 introduced type declarations for return and improved ones for parameters. They currently support a very limited kind of variance (only to no-type): | + | |
- | + | ||
- | <code php> | + | |
- | <?php | + | |
- | class A { function bar(stdClass $x){} } | + | |
- | class B extends A { function bar($x): stdClass{} } | + | |
- | </ | + | |
- | + | ||
- | However, this isn't currently matched by the equivalent abstract declarations: | + | |
- | + | ||
- | <code php> | + | |
- | <?php | + | |
- | abstract class A { abstract function bar(stdClass $x); } | + | |
- | abstract class B extends A { abstract function bar($x): stdClass; } | + | |
- | class C extends B { function bar($x): stdClass{} } | + | |
- | // Fatal error: Can't inherit abstract function A::bar() | + | |
- | // (previously declared abstract in B) | + | |
- | </ | + | |
- | + | ||
- | This RFC proposes to allow this, even if it has very few uses, and because there is no reason to disallow a compatible redefinition. | + | |
- | + | ||
- | Additionally, | + | |
- | + | ||
- | <code php> | + | |
- | interface A{ | + | |
- | function doSomething(); | + | |
- | } | + | |
- | + | ||
- | interface B extends A{ | + | |
- | function doSomethingElse(); | + | |
- | } | + | |
- | + | ||
- | abstract class AProxy implements A{ | + | |
- | abstract protected function getOrigin(): | + | |
- | function doSomething(){ | + | |
- | return $this-> | + | |
- | } | + | |
- | } | + | |
- | + | ||
- | // This phpdoc syntax has quirks in phpdocumentor | + | |
- | // apigen and phpstorm, and it's almost unmanageable | + | |
- | // as phpdoc interpreters have poor multiline support | + | |
- | // (imagine documenting all the parameters, the return | + | |
- | // type, all the throws...): | + | |
- | /** @method B getOrigin() */ | + | |
- | abstract class BProxy extends AProxy implements B{ | + | |
- | /** @return B */ // This is much better! | + | |
- | abstract protected function getOrigin(): | + | |
- | function doSomethingElse(){ | + | |
- | return $this-> | + | |
- | } | + | |
- | } | + | |
- | </ | + | |
- | + | ||
- | And, obviously, it will gain more uses when PHP will support a full-featured type variance. | + | |
- | + | ||
- | ===== Backward Incompatible Changes ===== | + | |
- | + | ||
- | None. | + | |
- | + | ||
- | ===== Proposed PHP Version(s) ===== | + | |
- | + | ||
- | 7.2 | + | |
- | + | ||
- | ===== Voting ===== | + | |
- | + | ||
- | 2/3 majority required. | + | |
- | + | ||
- | <doodle title=" | + | |
- | * Yes | + | |
- | * No | + | |
- | </ | + | |
- | + | ||
- | ===== Patches and Tests ===== | + | |
- | + | ||
- | N/A | + | |
- | + | ||
- | ===== References ===== | + | |
- | + | ||
- | [[https:// | + |
rfc/allow-constant-override.txt · Last modified: 2017/09/22 13:28 by 127.0.0.1