On Wed, Dec 6, 2017 at 2:32 PM Rowan Collins <rowan.coll...@gmail.com> wrote:
> On 06/12/2017 19:49, Nikita Popov wrote: > > Hi internals, > > > > I'd like propose optional support for explicitly marking by-reference > > argument passing at the call-site, in addition to the declaration-site > > > Hi Nikita, > > I approve of the aims of this proposal, but I do wonder if it would be a > bit awkward to reuse the syntax which people had to spend so much effort > removing in PHP 5.4 (you refer to it as a PHP 4 feature, but for many > people it's a much more recent memory). Aside from the frustration of > "why didn't we allow it in these cases all along", I can see people > being confused if it went from OK to fatal error to encouraged and maybe > even mandatory. > > Your future scope section mentions having more explicit "out" and > "inout" annotations; perhaps it would be better to skip ahead to these, > with new syntax, and more immediate benefits all round. Is there a > reason we can't do this right now? > > I imagine these working like the & annotation, with the following extra > rules: > > 1) Parameters marked "out" or "inout" in function definitions MUST also > be marked "out" or "inout" in calls to that function. > 2) Parameters marked "&" in function definitions MAY be marked with > "out" or "inout" in calls to that function. > 3) A variable passed to an "inout" parameter would raise a notice if it > was not defined before use, since it should have a value for the "in" part. > 4) A variable passed to an "out" parameter would NOT raise such a > notice, since the function call would be a valid initialisation. > 5) An already-initialised variable passed to an "out" parameter would be > set to null before calling the function. If the function never assigned > to it, it would remain null in the calling scope. > > Rule 2 allows for better interoperability between old and new code, and > I am imagining it also applying to core functions, so that this would > work without pre-initialising $matches: preg_match($pattern, $string, > out $matches); > > I'm not sure how reference-returning functions fit into this picture, > and there are probably other kinks to iron out, but it seems like it > would have a lot more benefits overall. > > Regards, Hi Nikita, I'd be more hesitant about seeing this syntax re-introdouced. Having recently been through the process of spending days to remove all the call-time by-reference fatals. Especially when the syntax proposed is generally ignored (excepting in the has &, but declaration doesn't). I do like the C-esque feel of having the declaration require a reference, and the call-side provide the reference, but the RFC lacks the warning where the declaration has reference, but call-side lacks it. However, adding this warning would probably anger everyone who did spend the time to remove all the call-time references only to now add them back in. I'd be with Rowan here. If the language is going to re-introduce old syntax as purely a visual aid, it would probably behoove us to actually look at the in/inout/out parameter types. I would be way more excited to see that play out, than having call-time-reference brought back. Cheers, -- Dave