On 23/02/2020 09:47, Nikita Popov wrote:
The prefer-ref/prefer-val thing is indeed a bit peculiar. It's an artifact of the current way of implicit by-reference passing, where the decision of whether to pass by-value or by-reference has to be made based on an "educated guess" at the call-site. That leaves us with always-val, always-ref, prefer-val and prefer-ref as the possible passing modes. In the explicit by-ref passing regime, the latter two consolidate, and we have by-val, by-ref and "either" as the options, which is a lot more obvious.


Thanks, that's a good summary of how this all relates to the RFC. If there is a use case for such a mode, perhaps we need a way to annotate userland functions as "either", so that they too can take advantage of the call-site annotation. In a sense, they'd be opting in to the pre-5.4 behaviour, for that particular parameter.



Instead of having __call(), what we really should have is __get_method().


That is a really interesting idea. The lack of function signature is currently a big turn-off for using __call, because it means manually recreating a lot of the unpacking and type checking that the language would normally do for you.



I believe we talked about this in some detail in the previous discussion on this topic. My basic stance on in/out is that it's *probably* not worth the complexity, unless it is part of an effort to eliminate references from PHP entirely (which would be hugely beneficial). Unfortunately I don't really see a clear pathway towards that. "out" parameters can remove one use-case of references, and I can see how that would work both in terms of semantics and implementation. The case of "inout" parameters is much more problematic. While these can nominally work without references, I don't see how they could do so efficiently (we would have to "move out" the value from the original location to avoid COW). Similarly, I don't have any answer to how &__get() and &offsetGet() would work without references.


That's fair enough. I guess the reason I've fixated on them is that I'd really like "out" parameters, independent of what else happens with references, in order to get the clear signal of "variable is initialised here" on a call like "preg_match($foo, $bar, out $matches)". That would make out parameters more attractive to build APIs around, e.g. when you want multiple strongly typed outputs from one call.

Even if we can't eliminate references entirely, perhaps there's value in reducing the use cases where they're necessary? A bit like how property accessor syntax wouldn't allow us to remove __get and __set, but would mean fewer cases where people needed to deal with them.


Regards,

--
Rowan Tommins (né Collins)
[IMSoP]

--
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to