2 hours later…
15:03
@Crell I think you have understood what I'm saying - basically establishing the valid template types for an instance at runtime and fixate an upper bound of validity according to type checks the class has been subject to. E.g. having a container $obj, then doing $obj->push(new A); $obj now is a container<required-types(A), permitted-types(mixed)>. Then doing $obj->push(new B); - Now it's a
container<required-types(A|B), permitted-types(mixed)>
.
Then we pass $obj to a function expecting
container<? extends A|B|C>
(to use java syntax for covariance). The type changes to container<required-types(A|B), permitted-types(A|B|C)>
. If we now do a $obj->push(new D); it will fail. Moving the container to a function accepting container<A|B|D> will also fail. … Something along these lines. It's complex to wrap the head around that TBH.
1 hour later…
16:14
Ah, I see. For objects, that seems unwise. The whole point of the typing is to allow compile-time or static-analysis time verification that things won't break. Doing it at runtime means, well, it won't break until runtime.
Arnaud is/was working on doing something like that for arrays, though. So you could type against `function foo(array<int> $is)` and then do `$a[] = 1; foo($a)` and it would pass, whereas `$a = [1, 'beep']` would fail at runtime. I'm still not convinced that's wise or performant.
Derick and I have discussed formal collection objects in core (I did a lot of language survey research on it last year), but that's on hold for now pending the results of Arnaud's generics research, as it would be way better to have real generics than a hacky semi-generics for collections only. (That's something Derick managed to make work, but real generics are better.)
1 hour later…
17:42
@Crell Yes, that's the PHP way to do things. And that's what you have static analysis for (psalm for example). The good part on that is that static analysis can be continuously improved, taking values, ranges, even some assertions on the data into account.
The runtime types are there to have hard guarantees, i.e. actual type assertions and the ability to optimize on it.
1 hour later…
19:06
I don't mean compile-time only generics / erased generics. I mean the type of an object changing out from under the code and so not being known even though it's declared, that is what strikes me as unwise.
« first day (4897 days earlier) ← previous day next day → last day (277 days later) »