Hey everyone, it's me, Wendell (that proposed this RFC in the first place).
I'm just using another e-mail because my other email m...@wendelladriel.com
is having some issues with the PHP email lists.

First of all, thanks for all the feedback so far on this proposal.
I'm seeing that the implementation would be far more complex than I thought
it would be.
I have two questions about this:

1. Should I move forward on creating the RFC for further discussion? If so,
I know that I need karma for that, I already created my Wiki account with
the email wendelladriel...@gmail.com and username wendell_adriel. In the
how-to guide says that I need to ask in this list for the needed Karma, so
if you think that I should move on with this RFC can someone give me the
needed karma for that?

2. It would be great to have someone else aboard with more experience in
the PHP source code and the RFC process since I'm a beginner and this seems
to be way more complex than I first thought. Is there anyone that wants to
work with me on the RFC proposal and the implementation if this should
proceed?

Thanks in advance.
Have an amazing day everyone.

*---*
*Best Regards,*
*Wendell Adriel.*
*Software Engineer **| Investor | Amateur Photographer | Musician | INFP*
*https://wendelladriel.com <https://wendelladriel.com>*


Em qua., 8 de fev. de 2023 às 14:40, Rowan Tommins <rowan.coll...@gmail.com>
escreveu:

> On Wed, 8 Feb 2023 at 00:13, Sergii Shymko <ser...@shymko.net> wrote:
>
> > I think, typed variables would be a necessary prerequisite for typed
> > arrays and eventually generics.
> > If my understanding is correct, the primary concern there is performance
> > overhead of iterating items for type checking.
> > With typed variables, type checking is done at assignment and passing
> > typed array around becomes lightweight.
> > It would be enough to type check against a known array item type without
> > iterating over items.
> >
> > For example:
> > function do_something(array<string> $strings) {
> >     ...
> > }
> > array<string> $names = ['John', 'Jane', 'Jake'];  // items are type
> > checked similar to variadic argument unpacking
> > sort($names);
> > do_something($names);  // lightweight type check as for scalar types
>
>
>
> This is probably more complicated to implement than you're imagining.
>
> Firstly, there is a key distinction between *variables* and *values*: when
> you say do_something($names), the receiving code in do_something doesn't
> know that the argument it was given is the variable $names, with type
> array<string>; it just receives the value ['John', 'Jane', 'Jake'].
>
> That leads to another distinction: the variable has a single type
> *constraint* ("must always point to a value matching this type"), but the
> value has multiple pieces of type *information* ("has been checked as
> meeting these different constraints"). Both can also be deduced using the
> relationships between types. For example:
>
> function do_something(array<string> $strings) {
>     ...
> }
> function filter_non_strings(array<mixed> $items): array<string> {
>     ...
> }
> array<string|int> $mixed_list = ['John', 42, 'Jane'];
> $mixed_list = filter_non_strings($mixed_list);
> // when calling filter_non_strings, we know that the value matches
> array<string|int>, so can deduce that it matches array<mixed> as well
> // when assigning the result back to $mixed_list, we know (from the return
> type check) that it matches array<string>, so can deduce that it matches
> array<string|int> as well
>
> do_something($mixed_list);
> // since the value hasn't changed since it was returned, it still matches
> array<string>, even though the variable doesn't have that constraint
>
> sort($mixed_list);
> // for this call to succeed, we need to know that the variable is an array;
> we can deduce that from knowing it matches array<string> or knowing that it
> matches array<string|int>
> // as a minimum, we need to assert that after modifying it by reference, it
> still matches array<string|int>, as required by $mixed_list
> // but do we also still know that it matches array<string>?
>
> It's all probably doable, but I think it's the other way around from your
> initial statement: working out how to cache type checks would be a
> pre-requisite for implementing local variable types.
>
> Regards,
> --
> Rowan Tommins
> [IMSoP]
>

Reply via email to