rfc:constants_in_traits
Differences
This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
rfc:constants_in_traits [2022/07/02 01:14] – add future scope: requiring specific interfaces or classes on traits sji | rfc:constants_in_traits [2022/08/04 19:17] (current) – Move the status to implemented sji | ||
---|---|---|---|
Line 1: | Line 1: | ||
====== PHP RFC: Constants in Traits ====== | ====== PHP RFC: Constants in Traits ====== | ||
- | * Version: 0.1 | + | * Version: 0.2.1 |
* Date: 2022-06-21 | * Date: 2022-06-21 | ||
* Author: Shinji Igarashi< | * Author: Shinji Igarashi< | ||
- | * Status: | + | * Status: |
* Implementation: | * Implementation: | ||
* First Published at: http:// | * First Published at: http:// | ||
Line 40: | Line 40: | ||
<code php> | <code php> | ||
- | intertface | + | interface |
public const FLAG_1 = 1; | public const FLAG_1 = 1; | ||
public function doFoo(int $flags): void; | public function doFoo(int $flags): void; | ||
Line 66: | Line 66: | ||
trait Foo { | trait Foo { | ||
public const FLAG_1 = 1; | public const FLAG_1 = 1; | ||
- | | + | |
+ | private const FLAG_3 | ||
public function doFoo(int $flags): void { | public function doFoo(int $flags): void { | ||
Line 74: | Line 75: | ||
if ($flags & self:: | if ($flags & self:: | ||
echo 'Got flag 2'; | echo 'Got flag 2'; | ||
+ | } | ||
+ | if ($flags & self:: | ||
+ | echo 'Got flag 3'; | ||
} | } | ||
} | } | ||
Line 218: | Line 222: | ||
CONSTANT as private; | CONSTANT as private; | ||
} | } | ||
+ | } | ||
+ | </ | ||
+ | |||
+ | ==== Can be used in Enum ==== | ||
+ | Enumerations can use traits having constants, which behave as if the constants were defined within the enumeration. | ||
+ | |||
+ | <code php> | ||
+ | trait T { | ||
+ | private const CONSTANT = 42; | ||
+ | } | ||
+ | |||
+ | // OK | ||
+ | enum E: int { | ||
+ | use T; | ||
+ | |||
+ | case CaseA = self:: | ||
} | } | ||
</ | </ | ||
Line 327: | Line 347: | ||
==== Rust ==== | ==== Rust ==== | ||
- | Rust has associated constants. | + | Rust has associated constants. |
==== C++ ==== | ==== C++ ==== | ||
Line 336: | Line 356: | ||
- | ===== Proposed Voting Choices | + | ===== Vote ===== |
- | A 2/3 majority is needed for this RFC to pass. Voting | + | A 2/3 majority is needed for this RFC to pass. Voting |
+ | |||
+ | <doodle title=" | ||
+ | * Yes | ||
+ | * No | ||
+ | </ | ||
rfc/constants_in_traits.txt · Last modified: 2022/08/04 19:17 by sji