I suppose you don't actually need the is
op; you can use the implements &|
extends keywords :)
Best,
Richard Miles
> On Jun 26, 2024, at 5:26 PM, Richard Miles <[email protected]> wrote:
>
>> We've done some initial work related to this as part of PHP Foundation work:
>> <https://github.com/derickr/php-src/tree/collections/Zend/tests/collection>
>
> After reviewing the PR I don't think this accurately captures what we're attempting
> to do/discuss.
> Are there other branches you could share? You’ve posed a lot of new syntax. I have questions.
>
> collection(Dict) Articles<string => Article> {}
>
> The code above is limiting compared to the posed syntax in this thread. Since your just working
> on providing a specific datatype with a custom syntax. What am I supposed to be able todo inside the
> {}? Why not?
>
> collection(Dict<Article>) Articles {}
>
> or just
>
> Dict<Article> Articles {}
> Seq<Article> Articles {}
>
> and then there's the completely new syntax? Am I supposed to be able to add methods in
> this block?
>
> class Articles extends Dict<Article> {}
>
> If I'm not then it should read more like the following:
>
> $a = (Dict<Article>) [];
>
> ____________________________________________________________
>
> But this all feels off-topic. Because, we need to get Typed Array syntax!
>
>
> interface iArrayA ['a' => string ]
> interface iArrayB implements iArrayA ['b' => string, 'c' => ?string ]
>
>
> $array = iArrayA [
> ‘a’ => ‘hello'
> ];
> // reads the same as a typecast
> $array = (iArrayA &| iArrayB) [
> ‘a’ => ‘hello'
> ];
>
> // It’s essentially like a typecast, which should probably be allowed. If the set of possible
> values needs to increase, a typecast would do it.
>
> class A {
> public iArrayB $array = [
> ‘a’ => ‘hello’,
> ‘b’ => ‘world'
> ];
> }
>
> If generics and the is operator get passed then one could in theory do.
>
> class A <T is iArrayA>{
> public T $array = [
> ‘a’ => ‘hello’
> ];
> }
>
> $a = new A<iArrayB>;
>
>
> Best,
> Richard Miles