On Thu, Jul 25, 2019 at 3:14 PM Rowan Collins <rowan.coll...@gmail.com> wrote:
> On Thu, 25 Jul 2019 at 13:32, Nikita Popov <nikita....@gmail.com> wrote: > > > I think it can either go forward as-is, in that it constitutes the first > > step towards bringing sanity to by-reference passing in the long term. > > > > > Hi Nikita, > > As I mentioned before, I think this RFC is 10 years too late: if this goes > ahead, we'll be telling a lot of people "You know all those reference > annotations you removed when you upgraded to PHP 5.4? You have to put them > all back again now!" > > To be clear, forcing a parameter to be by-reference against the signature > of the called function was a bad feature, and this proposal would have been > better. But without a time machine, I think this will cause more confusion > than it brings value. > > Adding "out" and "inout" keywords, as mentioned in "future scope", is a > much more powerful change, won't require any opt-in modes or breaks to > existing code, and would be looking forward rather than backward. It's hard > to see how tweaking the meaning of "&" will lead us closer to that, making > it feel more like "alternative" than "future". > While the out/inout keywords are conceptually nice, I don't think they really change anything regarding the migration path. In your previous mail you mentioned that we could make these keywords required if they are used on the declaring function: But that does not solve the problem of existing functions. I think nowadays it is well known that by-reference passing is to be avoided and I don't see it particularly commonly in user code. By-reference passing is mainly used when it is needed to interact with existing by-reference functions such as preg_match(). We can hardly switch these functions to use out/inout if we require the corresponding keyword on the call-site. This proposal (in conjunction with the option to make it required) would solve the main issues I have with the by-reference passing implementation -- the out/inout approach is a refinement over that, but I'm not convinced that it a worthwhile refinement relative to the language and engine complexity it will introduce. It would be a necessary step if we had plans to eliminate references from PHP entirely, but despite how much I dislike PHP references, I don't think that eliminating references entirely is possible even on a very long time-scale. Nikita