Re: [Zend Engine 2] RE: [PHP-DEV] Re: [Zend Engine 2] Re: [PHP-DEV] [RESENT] [PATCH] Allow constants / expressions to be passed by reference]
| From: | Shane Caraveo | Date: | Wed, 29 May 2002 18:23:45 +0000 |
| Subject: | Re: [Zend Engine 2] RE: [PHP-DEV] Re: [Zend Engine 2] Re: [PHP-DEV] [RESENT] [PATCH] Allow constants / expressions to be passed by reference] | ||
| References: | 1 | Groups: | php.dev |
| Request: | Send a blank email to php-dev+get-84541@lists.php.net to get a copy of this message | ||
Ahh yes, I've been bitten by this limitation a few times, quite agravating. I would definitly like to have this work.
Shane
phpsurf wrote:
the problem is that if you define some function : function someFunc(&myParam) { ... } then you can call : someFunc($someVar); but not : define("MY_CONSTANT", 0); someFunc(MY_CONSTANT); the goal is not to pass a constant by reference, but to be allowed to (exceptionnaly) pass a constant as a parameter to a function that was designed to receive parameters by reference. and this could also let people define default values for params and still have them passed by reference ...-----Original Message----- From: Andi Gutmans [mailto:andi@zend.com] Sent: mercredi 29 mai 2002 17:26 To: Stig S. Bakken; Jason T. Greene Cc: php-dev@lists.php.net; engine2@lists.zend.com Subject: [PHP-DEV] Re: [Zend Engine 2] Re: [PHP-DEV] [RESENT] [PATCH] Allow constants / expressions to be passed by reference] 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:______________________________________________________________________________ ifrance.com, l'email gratuit le plus complet de l'Internet ! vos emails depuis un navigateur, en POP3, sur Minitel, sur le WAP... http://www.ifrance.com/_reloc/email.emailifIf 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:it has notDue to this patch being sent during the msession discussion,ability to modifybeen noticed, so I am resending. -Jason ----From: Jason Greene <jason@php.net> To: php-dev@lists.php.net Cc: zeev@zend.com, andi@zend.com Subject: [PHP-DEV] [PATCH] Allow constants / expressions to be passedby referenceDate: 25 May 2002 02:18:52 -0500 Problem ------- There are some scenarios where a function requires theparameters canparameters that may also be optional. Optional parameters work well, except in the scenario where all of the pass by referencemust be passedbe optional. ex the socket_select() function. Since select is argument-result, all three arrays that are taken as input-- PHP Development Mailing List <http://www.php.net/> To unsubscribe, visit: http://www.php.net/unsub.phpby 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.cvariables can be passed by reference");--- 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(EX(opline)->extended_value==ZEND_DO_FCALL_BY_NAME+ 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: - ifARG_SHOULD_BE_SENT_BY_REF(EX(opline)->op2.u.opline_num, EX(fbc), EX(fbc)->common.arg_types)) {- &&"Cannot pass parameter %d by reference", EX(opline)->op2.u.opline_num);- zend_error(E_ERROR,zend_ptr_stack_push(&EG(argument_stack), varptr);- } { zval *valptr; zval *value;@@ -2329,7 +2325,8 @@variables can be passed by reference");NEXT_OPCODE(); } - zend_error(E_ERROR, "Onlyuninitialized variable */+ /* Should only occur with an+ 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