On 09/23/2011 03:41 PM, Daniel K. wrote:
On 09/23/2011 02:28 PM, Etienne Kneuss wrote:
On Fri, Sep 23, 2011 at 14:06, Daniel K. wrote:
When a built-in function is defined with ZEND_SEND_PREFER_REF, PHP will
issue a strict warning if you use an assignment expression as the parameter.
The patch looks strange to me, why would you only consider stuff like
foo($a = 2) ? what about passing any other expressions:
foo(array(..)), foo(funcNotReturningARef()) etc... ?
[*SNIP Lengthy description of why the patch is right*]
To me it makes not much sense to distinguish different non-ref
expressions in that regard, they should all be handled the same.
It makes very much sense to make the distinction, as not all expressions
are made the same. Only IS_VAR and IS_CV ones are considered candidates
for passing by reference in zend_do_pass_param()
However, it can be done with less complexity, we only have to make sure
that the function arguments that the lexer sends to zend_do_pass_param
is not promoted to be sent by reference if the lexer already has decided
that you did not specify a variable. See: Zend/zend_language_parser.y ->

In other words, only consider promoting to send by reference if the
argument passed to the function is not of type ZEND_SEND_VAL.

--- a/Zend/zend_compile.c
+++ b/Zend/zend_compile.c
@@ -2096,7 +2096,7 @@ void zend_do_pass_param(znode *param, zend_uchar
op, int offset TSRMLS_DC) /* {{

if (function_ptr) {
if (ARG_MAY_BE_SENT_BY_REF(function_ptr, (zend_uint) offset)) {
- if (param->op_type & (IS_VAR|IS_CV)) {
+ if (param->op_type & (IS_VAR|IS_CV) && original_op != ZEND_SEND_VAL) {
send_by_reference = 1;
if (op == ZEND_SEND_VAR && zend_is_function_or_method_call(param)) {
/* Method call */

Thanks for questioning my patch, and making me recheck what I was doing,
so that this minimal patch could come to life.

This still passes the test-suite with flying colours.

As a bonus this version of the fix applies to both 5.3-latest and

Whether we want the actual error on some of our functions like
current()/end() etc.. is another question, but that should be fixed at
a totally different level.
I think I misunderstood you last time around.

I am of the opinion that the strict warning in question is completely
bogus. If the arginfo says: ZEND_SEND_PREFER_REF, Zend had better shut
up when a _value_ is passed.

Daniel K.

Search Discussions

Discussion Posts


Follow ups

Related Discussions

Discussion Navigation
viewthread | post
posts ‹ prev | 5 of 15 | next ›
Discussion Overview
groupphp-internals @
postedSep 23, '11 at 12:06p
activeOct 7, '11 at 6:51p



site design / logo © 2022 Grokbase