On 3 January 2018 at 21:26, Rowan Collins <rowan.coll...@gmail.com> wrote: > Hi Michael, > > On 02/01/2018 10:35, Michael Morris wrote: >> >> I would like to propose a clean way to add some strong typing to PHP in a >> manner that is almost fully backward compatible (there is a behavior >> change >> with PHP 7 type declarations). As I don't have access to the add RFC's to >> the wiki I'll place this here. > > > Thanks for putting this together. Perhaps unlike Andreas, I think it is good > to look at typing changes as a unified framework, rather than considering > "typed properties", "typed variables", etc, as separate concerns. If we > don't, there is a real risk we'll end up making decisions now that hobble us > for future changes, or over-complicating things in one area because we're > not yet ready to make changes in another.
I think the best strategy is to develop a greater vision of where we want to go, and then identify manageably small steps that move us in this direction, and that do not create conflicts in the future. This means we are both right. I still think the following are good "small steps": - typed properties with type lock - typed local variables with type lock - discussion whether and when parameters should be type-locked in the function body. Of course there should be consistency between those steps. You are right, we also need to consider when these types should be validated, and/or how the variables would be implemented. Perhaps we could actually create a system where type-locked variables use less memory, because they no longer need to store the type of the variable? E.g. a type-locked integer would only use the 64 bit or whichever size we currently use to store the actual number. > The biggest issue with any proposal, though, is going to be performance. I > don't think this is an incidental detail to be dealt with later, it is a > fundamental issue with the way type hints in PHP have evolved. PHP is > extremely unusual, if not unique, in exclusively enforcing type constraints > at runtime. Other languages with "gradual typing" such as Python, Hack, and > Dart, use the annotations only in separate static analysers and/or when a > runtime debug flag is set (similar to enabling assertions). A system where all variables are type-locked could in fact be faster than a system with dynamically typed variables. Depends on the implementation, of course. I imagine it would be a lot of work to get there. -- PHP Internals - PHP Runtime Development Mailing List To unsubscribe, visit: http://www.php.net/unsub.php