Re: [RFC] Explicit call-site pass-by-reference (again)

From: Date: Sat, 14 Mar 2020 20:08:04 +0000
Subject: Re: [RFC] Explicit call-site pass-by-reference (again)
References: 1  Groups: php.internals 
Request: Send a blank email to internals+get-109019@lists.php.net to get a copy of this message
Hi internals, One idea I had that was related to this (but not in the scope of this RFC) would be adding a way to force the interpreter to treat an argument (variable, array field, property access, etc) as being passed by value, and refuse to modify it by reference (e.g. emit a notice and create a separate reference (or throw an Error)) i.e. instead of using the opcode SEND_VAR_EX, use a brand new opcode kind SEND_VAR_BY_VALUE that would do that, if the method signature was unknown. - Currently, php emits a notice and creates a temporary reference for non-variables, such as when passing the result of a function returning a non-reference to a reference parameter. - I assume SEND_VAR_BY_VALUE is equivalent to the new opcode needed if a subsequent RFC made call-site pass-by-reference mandatory in a given file. Possible syntaxes (only within argument lists): ``` $a->someMethod(*$foo); $a->someMethod(&&$foo); $a->someMethod(\$foo); $a->someMethod(identity($foo)); // add a new keyword such as identity or value $a->someMethod(=$foo); ``` Context: From the current thread's RFC https://wiki.php.net/rfc/explicit_send_by_ref > In fact, our inability to determine at compile-time whether a certain argument is passed > by-value or by-reference is one of the most significant obstacles in our ability to analyze and > optimize compiled code I suggested this because it would be useful for optimizing frequently used code (after profiling it (e.g. with phpspy) and checking opcache debug output), especially in frequently called functions/methods. I'd prefer a declare directive (or edition) to make call-site pass-by-reference mandatory to pass by reference over this suggestion, though. - Tyson

« previous php.internals (#109019) next »