On Wed, Feb 8, 2023 at 6:23 PM Wendell Adriel
<wendelladriel...@gmail.com> wrote:
>
> Hello everyone.
> I created the Draft for this RFC:
> https://wiki.php.net/rfc/local_variable_types
> I'd love to hear your thoughts on this before proceeding further.
> If anything should be changed or updated just let me know.
> I'll be happy to help with anything related to this.
>
> *---*
> *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 15:54, Alexandru Pătrănescu <
> dreal...@gmail.com> escreveu:
>
> > On Tue, Feb 7, 2023 at 10:21 PM Mark Baker <m...@demon-angel.eu> wrote:
> >
> > > On 07/02/2023 20:53, Olle Härstedt wrote:
> > > > No not really. I'd expect it behave similar to function argument
> > > > type-hinting in PHP, that is, runtime checks, but where the notation
> > > > can be used by external tools.
> > >
> > > The big difference is that the current checking for function arguments
> > > is only necessary when a function is called; but that checking for
> > > local-scoped variables would be required on every assignment to a
> > > variable, or operation that can change a variable value; and that
> > > becomes more problematic with the potential need for union types.
> > >
> > >
> > Hi Mark,
> >
> > I saw that you and Olle were discussing that type checking should be
> > similar with functions typed parameters .
> > But in reality, it should be implemented more like typed properties.
> >
> > Actually that's already possible with something like
> > https://3v4l.org/T6GFS
> > function &declare_int(int $value) {
> >     static $references = [];
> >
> >     $valueWrapper = new class(5) {
> >         public function __construct(public int $value) {
> >         }
> >     };
> >     $references[] = $valueWrapper;
> >
> >     return $valueWrapper->value;
> > }
> >
> > $intVariable = &declare_int(0);
> >
> > $intVariable = 42; // works
> > $intVariable = 'test'; // fails
> >
> >
> > Even the PHP_INT_MAX works (it fails).
> >
> > To give credit, I saw it discussed few years ago on twitter and here you
> > can see a nice playground implementation: https://github.com/azjezz/typed/
> > I don't see a bug technical performance downside, other than the wrapper
> > class references that you need to have a management for.
> > I think an implementation in C would be not less performant than how
> > properties types are checked.
> >
> > Regards,
> > Alex
> >

For `array<int, string>` why not just use `list`?

Robert Landers
Software Engineer
Utrecht NL

--
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: https://www.php.net/unsub.php

Reply via email to