Re: Typed array properties V2

From: Date: Fri, 24 Jan 2020 21:43:02 +0000
Subject: Re: Typed array properties V2
References: 1 2 3  Groups: php.internals 
Request: Send a blank email to internals+get-108236@lists.php.net to get a copy of this message
> On Jan 24, 2020, at 14:27, Mike Schinkel <mike@newclarity.net> wrote: > > Thus far we have discussed that implementation of type checking for arrays would be too costly > from a performance perspective and that there is no good solution that is not extremely complicated > to implement. > > Given that, can we consider an alternative? > > ALLOW the use of a syntax for typed arrays — whether it be type[] or [type] — but only > validate that it is an array and that the "type" is in fact a type, but don't > actually validate that each element is the correct type. > > This would allow those of us who want to start documenting specific usage using type hints to > be able to do so instead of what we currently have to do is PHPDoc one way and type hint with > "array." It would also allow IDEs like PhpStorm to add support. > > Is this something the PHP community would consider? > > -Mike My opinion is that if you're going to declare the type of a variable, you have to have some way of enforcing that the type _really_ is what you say it is. Otherwise, the type information is basically a lie, and you're much better off without it. If PHP's type system can't or won't enforce the type fully as declared, then it's much better to have phpdocs that assert what the type "really" is, like we do now. I have some ideas on what might be reasonably performant array type enforcement, but having not fully read the thread, I'll keep that to myself until I have a chance to see that I have anything that's actually novel. -John

« previous php.internals (#108236) next »