rfc:internal_method_return_types
Differences
This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
rfc:internal_method_return_types [2021/03/22 11:57] – kocsismate | rfc:internal_method_return_types [2021/05/14 13:57] (current) – kocsismate | ||
---|---|---|---|
Line 2: | Line 2: | ||
* Date: 2021-03-06 | * Date: 2021-03-06 | ||
* Author: Máté Kocsis < | * Author: Máté Kocsis < | ||
- | * Status: | + | * Status: |
* Implementation: | * Implementation: | ||
+ | * Target Version: PHP 8.1 | ||
===== Introduction ===== | ===== Introduction ===== | ||
Line 67: | Line 68: | ||
</ | </ | ||
- | Unfortunately, | + | Unfortunately, |
<code php> | <code php> | ||
Line 75: | Line 76: | ||
* @return DateTime|false | * @return DateTime|false | ||
*/ | */ | ||
- | #[SuppressReturnTypeNotice] | + | #[ReturnTypeWillChange] |
public function modify(string $modifier) { return false; } | public function modify(string $modifier) { return false; } | ||
} | } | ||
Line 86: | Line 87: | ||
As the tentative return type declarations in question wouldn' | As the tentative return type declarations in question wouldn' | ||
- | ===== Backward Incompatible Changes ===== | + | On the other hand, two new methods are proposed for addition to the '' |
- | + | ||
- | In PHP 8.1, an '' | + | |
- | + | ||
- | ===== Exposing | + | |
- | + | ||
- | The same mechanism can be exposed for userland methods so that libraries can also benefit from it when preparing for adding return type declarations. For this purpose, a '' | + | |
<code php> | <code php> | ||
- | class Foo | + | class ReflectionMethod |
{ | { | ||
- | | + | public function |
- | | + | |
- | | + | |
- | return " | + | |
- | } | + | |
} | } | ||
- | |||
- | class Foo2 extends Foo | ||
- | { | ||
- | public function bar() | ||
- | { | ||
- | } | ||
- | } | ||
- | |||
- | class Foo3 extends Foo | ||
- | { | ||
- | # | ||
- | public function bar(): string|false | ||
- | { | ||
- | return []; | ||
- | } | ||
- | } | ||
- | |||
- | $foo2 = new Foo2(); | ||
- | $foo2-> | ||
- | |||
- | $foo3 = new Foo3(); | ||
- | $foo3-> | ||
- | |||
- | // Deprecated: Declaration of Foo2::bar() should be compatible with Foo::bar(): string | ||
- | // Fatal error: Uncaught TypeError: Foo3:: | ||
</ | </ | ||
- | By attaching the '' | + | ===== Backward Incompatible Changes ===== |
- | It should also be highlighted that '' | + | In PHP 8.1, an '' |
- | <code php> | + | ===== Vote ===== |
- | class Foo | + | |
- | { | + | |
- | # | + | |
- | public function bar(): string | + | |
- | { | + | |
- | return " | + | |
- | } | + | |
- | } | + | |
- | class Foo2 extends Foo | + | Voting started 2021-04-22 and ends 2021-05-06 UTC. The vote requires 2/3 majority to be accepted. |
- | { | + | |
- | # | + | |
- | public function bar(): array | + | |
- | { | + | |
- | return []; | + | |
- | } | + | |
- | } | + | |
- | class Foo3 extends Foo2 | + | <doodle title="Add return type declarations |
- | { | + | * Yes |
- | public function bar(): string | + | * No |
- | { | + | </doodle> |
- | return | + | |
- | } | + | |
- | } | + | |
- | + | ||
- | // Fatal error: Declaration of Foo3:: | + | |
- | </ | + | |
- | + | ||
- | This behaviour is necessary to keep backward compatibility, | + | |
- | + | ||
- | In addition to the '' | + | |
- | + | ||
- | <code php> | + | |
- | class ReflectionMethod | + | |
- | { | + | |
- | public function hasTentativeReturnType(): | + | |
- | public function getTentativeReturnType(): | + | |
- | } | + | |
- | </code> | + | |
- | + | ||
- | ===== Vote ===== | + | |
- | Primary vote: Add return type declarations for internal methods in the proposed schedule? The vote requires 2/3 majority to be accepted. | ||
- | Secondary vote: Add the '' |
rfc/internal_method_return_types.1616414273.txt.gz · Last modified: 2021/03/22 11:57 by kocsismate