Okay I'll try and look at your patch in the next couple of days. It's quite sensitive code which this changes (has harmless as it might seem) so I need some time to read over it.
Andi At 11:37 29/05/2002 -0500, Jason T. Greene wrote: >Andi, > >I do not see how this is semantically incorrect, or how it is that much >different than allowing default values for pass by reference arguments. >IMO The only useful reason to deny passing a constant/expression in a >function is to provide a warning message. Some of the problems I >outlined in my post can be solved using default values(only using ZE2, >which allows defaults on reference args); however, default values only >solve rightmost optional parameters. i.e. there is no way to do: > >function a($arg1, $arg2="blah", $arg3="blah"){} > > >a(1, ,3) > >In respect to not passing by reference, this problem is solved by doing >the following > >function magic_function($var1, $var2, $var3) { > // Note just an example - I would usually use func_get_args... > if ($var2 === NULL) { > $var2 = "blah"; > } >} > >magic_function(1, NULL, 3); > >This technique of course will not work with the current semantics of not >allowing constants/expressions to pass by reference. > >-Jason > > > > > >On Wed, 2002-05-29 at 10:26, Andi Gutmans wrote: > > I don't see any reason to allow passing non-variables by reference. > > It is semantically incorrect. > > > > Andi > > > > At 09:40 29/05/2002 +0200, Stig S. Bakken wrote: > > >If this patch doesn't break anything, and it doesn't give us any > > >difficulties with ZE2 or major design issues, I'm +1. > > > > > > - Stig > > > > > >On Tue, 2002-05-28 at 21:12, Jason T. Greene wrote: > > > > Due to this patch being sent during the msession discussion, it has not > > > > been noticed, so I am resending. > > > > > > > > > > > > -Jason > > > > ---- > > > > > > > > > > > From: Jason Greene <[EMAIL PROTECTED]> > > > > To: [EMAIL PROTECTED] > > > > Cc: [EMAIL PROTECTED], [EMAIL PROTECTED] > > > > Subject: [PHP-DEV] [PATCH] Allow constants / expressions to be passed > > > by reference > > > > Date: 25 May 2002 02:18:52 -0500 > > > > > > > > Problem > > > > ------- > > > > > > > > There are some scenarios where a function requires the ability to > modify > > > > parameters that may also be optional. Optional parameters work well, > > > > except in the scenario where all of the pass by reference > parameters can > > > > be optional. ex the socket_select() function. Since select is > > > > argument-result, all three arrays that are taken as input must be > passed > > > > by reference, yet any can be excluded. So for example if you were > > > > calling socket_select with a read socket array, a write socket array, > > > > yet no exception array (quite common), you are currently forced to do > > > > something like the following: > > > > > > > > $wfds = array($sock1, $sock2); > > > > $rfds = array($sock3, $sock4); > > > > $null = NULL; > > > > > > > > socket_select($rfds, $wfds, $null); > > > > > > > > > > > > I have ran into this problem before several times while developing in > > > > user space. (Especially when passing around semi-complex data > > > > structures) > > > > > > > > Proposed Solution > > > > ------------------ > > > > > > > > Allow all expressions to be passed by reference. This will allow > > > > something like the following > > > > > > > > function normalize(&$element_tree, &$node_mapping, $max_depth){ > > > > //Code > > > > } > > > > > > > > normalize($my_tree, NULL, 25000); > > > > > > > > > > > > Patch > > > > ------ > > > > > > > > I have attached a patch against ZE2 that accomplishes this. > > > > > > > > > > > > Thanks, > > > > -Jason > > > > > > > > > > > > > > > > > > > > > > > > ---- > > > > > > > > > > > Index: zend_compile.c > > > > =================================================================== > > > > RCS file: /repository/ZendEngine2/zend_compile.c,v > > > > retrieving revision 1.285 > > > > diff -u -r1.285 zend_compile.c > > > > --- zend_compile.c 23 Apr 2002 18:06:53 -0000 1.285 > > > > +++ zend_compile.c 25 May 2002 06:45:21 -0000 > > > > @@ -1271,7 +1271,7 @@ > > > > op = ZEND_SEND_REF; > > > > break; > > > > default: > > > > - zend_error(E_COMPILE_ERROR, "Only > > > variables can be passed by reference"); > > > > + op = ZEND_SEND_VAR; > > > > break; > > > > } > > > > } > > > > Index: zend_execute.c > > > > =================================================================== > > > > RCS file: /repository/ZendEngine2/zend_execute.c,v > > > > retrieving revision 1.341 > > > > diff -u -r1.341 zend_execute.c > > > > --- zend_execute.c 8 May 2002 18:43:19 -0000 1.341 > > > > +++ zend_execute.c 25 May 2002 06:45:25 -0000 > > > > @@ -2292,10 +2292,6 @@ > > > > NEXT_OPCODE(); > > > > } > > > > case ZEND_SEND_VAL: > > > > - if > > > (EX(opline)->extended_value==ZEND_DO_FCALL_BY_NAME > > > > - && > > > ARG_SHOULD_BE_SENT_BY_REF(EX(opline)->op2.u.opline_num, EX(fbc), > > > EX(fbc)->common.arg_types)) { > > > > - zend_error(E_ERROR, > > > "Cannot pass parameter %d by reference", EX(opline)->op2.u.opline_num); > > > > - } > > > > { > > > > zval *valptr; > > > > zval *value; > > > > @@ -2329,7 +2325,8 @@ > > > > > > > zend_ptr_stack_push(&EG(argument_stack), varptr); > > > > NEXT_OPCODE(); > > > > } > > > > - zend_error(E_ERROR, "Only > > > variables can be passed by reference"); > > > > + /* Should only occur with an > > > uninitialized variable */ > > > > + goto send_by_var; > > > > } > > > > NEXT_OPCODE(); > > > > case ZEND_SEND_VAR: > > > > > > > > ---- > > > > > > > > > > > -- > > > > PHP Development Mailing List <http://www.php.net/> > > > > To unsubscribe, visit: http://www.php.net/unsub.php > > > > ---- > > > > > > > > > > > -- > > > > PHP Development Mailing List <http://www.php.net/> > > > > To unsubscribe, visit: http://www.php.net/unsub.php > > > > > > -- > > PHP Development Mailing List <http://www.php.net/> > > To unsubscribe, visit: http://www.php.net/unsub.php > > -- PHP Development Mailing List <http://www.php.net/> To unsubscribe, visit: http://www.php.net/unsub.php