Guilliam,

On Wed, Mar 30, 2022 at 7:50 AM Guilliam Xavier <guilliam.xav...@gmail.com>
wrote:

> Hi Mark,
>
> I have updated the RFC https://wiki.php.net/rfc/typed_class_constants with
>>>> more details and examples from this thread, and updated the RFC status
>>>> to
>>>> Under Discussion. Hopefully the updated RFC helps answer questions and
>>>> clarifies what the proposal includes.
>>>>
>>>
> Thanks (I assume that you talked with the original author) -- not sure if
> you should have started a new thread with the "[RFC]" tag in the subject?
>

I will address the issues from you and Alex in the RFC page, then start a
new thread with "[RFC]" since you are correct this has moved past
initial testing-the-waters and is now into the discussion phase about the
RFC. I reached out multiple times to the original author but have not
received a response. I did leave Benas as an author to give him credit for
the work he did.


>
>
>> I think you should also update the "Supported types" section.
>>> Starting with enums, constants can also be objects. Once a good
>>> technical solution is found, any object would be supported probably
>>> https://wiki.php.net/rfc/new_in_initializers#future_scope
>>> I think that only void, never and callable types should not be
>>> supported, just like on properties.
>>>
>>
>> I have updated the "Supported types" to list out all types that are
>> supported and which types are not supported.
>>
>
> A few comments, by subsection:
>
>   - **Supported types**: This corresponds to the types currently allowed
> for const values (as well as unions thereof) except it [still] doesn't
> mention enums (which internally are classes implementing the `UnitEnum`
> interface, and whose values are ultimately of `object` type) although
> currently allowed. It also doesn't mention `mixed` (used later in examples).
>   - **Strict and coercive typing modes**: I didn't understand it on first
> read; I had to read the later "Constant values" section and compare both
> with
> https://wiki.php.net/rfc/typed_properties_v2#strict_and_coercive_typing_modes
> and https://wiki.php.net/rfc/typed_properties_v2#default_values
>   - **Inheritance and variance**: Several occurrences of "Class constants"
> should probably be "*Typed* class constants". Also, I still think that
> `protected bool $isExtinct` is *not* a good parallel to `public const bool
> CAN_FLY` (see my previous message).
>   - **Constant values**: You should probably remove the `iterable` example
> now [and maybe add an `enum` one].
>

Thanks for the input, I'll work on addressing those.


>
>
>> Constants cannot be objects since objects are mutable, so typed constants
>> will not be allowed to be an enum (which is technically an object). A typed
>> constant _may_ be an enum value though, so the following example will be
>> valid:
>>
>> ```
>> enum Fruit
>> {
>>     case Apple;
>>     case Banana;
>> }
>>
>> class Colors
>> {
>>     protected const string RED = Fruit::Apple;
>>     protected const string YELLOW = Fruit::Banana;
>> }
>> ```
>>
>
> This is incorrect, `Fruit::Apple` is of type `Fruit` (ultimately
> `object`), not `string`. But it is *not* mutable, and *is* allowed as a
> const value currently.
>

Yes, Alex also identified this issue in my examples, I will correct that
and include enum examples in an updated RFC. I will do that before starting
an "[RFC]" thread.


>
> Besides, I realized that the RFC is [only] for *class* constants; what
> about *namespaced (and global)* constants?
>

Ah yes, I hadn't considered expanding this RFC to namespaced and global
constants. Let me mull over implementation syntax for those and include
them in the RFC. My initial reaction is to not include those in this RFC,
keeping the scope to just class constants. If there is value in typing
namespaced and global constants, then another RFC could add those.

Once I have all these new issues figured out and the RFC updated, I'll
start that new thread.


>
> Regards,
>
> --
> Guilliam Xavier
>

Reply via email to