[PHP-DEV] Re: [Zend Engine 2] Re: [PHP-DEV] [RESENT] [PATCH] Allow constants / expressions to be passed by reference]

2002-05-29 Thread Andi Gutmans

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.c23 Apr 2002 18:06:53 -  1.285
  +++ zend_compile.c25 May 2002 06:45:21 -
  @@ -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.c8 May 2002 18:43:19 -   1.341
  +++ zend_execute.c25 May 2002 06:45:25 -
  @@ -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




RE: [PHP-DEV] Re: [Zend Engine 2] Re: [PHP-DEV] [RESENT] [PATCH] Allow constants / expressions to be passed by reference]

2002-05-29 Thread phpsurf

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:[EMAIL PROTECTED]]
 Sent: mercredi 29 mai 2002 17:26
 To: Stig S. Bakken; Jason T. Greene
 Cc: [EMAIL PROTECTED]; [EMAIL PROTECTED]
 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:
 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.c23 Apr 2002 18:06:53 -  1.285
   +++ zend_compile.c25 May 2002 06:45:21 -
   @@ -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.c8 May 2002 18:43:19 -   1.341
   +++ zend_execute.c25 May 2002 06:45:25 -
   @@ -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

Re: [PHP-DEV] Re: [Zend Engine 2] Re: [PHP-DEV] [RESENT] [PATCH] Allow constants / expressions to be passed by reference]

2002-05-29 Thread brad lafountain

I have ran into this limitation too

or something like

foo();
or
foo($bar);

function foo($bar = null)
{
}


--- Andi Gutmans [EMAIL PROTECTED] 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.c23 Apr 2002 18:06:53 -  1.285
   +++ zend_compile.c25 May 2002 06:45:21 -
   @@ -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.c8 May 2002 18:43:19 -   1.341
   +++ zend_execute.c25 May 2002 06:45:25 -
   @@ -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
 


__
Do You Yahoo!?

Re: [PHP-DEV] Re: [Zend Engine 2] Re: [PHP-DEV] [RESENT] [PATCH] Allow constants / expressions to be passed by reference]

2002-05-29 Thread Sebastian Bergmann

brad lafountain wrote:
 function foo($bar = null)
 {
 }

  This has already been fixed for the Zend Engine 2:

* Parameters that are passed by reference to a function
  may now have default values.

  Example:

?php
function my_function($var = null) {
 if ($var === null) {
 die('$var needs to have a value');
 }
}
?

  (Source: /ZendEngine2/ZEND_CHANGES)

-- 
  Sebastian Bergmann
  http://sebastian-bergmann.de/ http://phpOpenTracker.de/

  Did I help you? Consider a gift: http://wishlist.sebastian-bergmann.de/

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




Re: [PHP-DEV] Re: [Zend Engine 2] Re: [PHP-DEV] [RESENT] [PATCH]Allow constants / expressions to be passed by reference]

2002-05-29 Thread Jason T. Greene

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.c23 Apr 2002 18:06:53 -  1.285
   +++ zend_compile.c25 May 2002 06:45:21 -
   @@ -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.c8 May 2002 18:43:19 -   1.341
   +++ zend_execute.c25 May 2002 06:45:25 -
   @@ -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);
 

[Fwd: [PHP-DEV] Re: [Zend Engine 2] Re: [PHP-DEV] [RESENT] [PATCH] Allow constants / expressions to be passed by reference]]

2002-05-29 Thread Sebastian Bergmann

  Hamster ate my mail? Resent, just in case.

Sebastian Bergmann wrote:
 brad lafountain wrote:
 function foo($bar = null)
 {
 }

  This has already been fixed for the Zend Engine 2:

 * Parameters that are passed by reference to a function
   may now have default values.

   Example:

 ?php
 function my_function($var = null) {
  if ($var === null) {
  die('$var needs to have a value');
  }
 }
 ?

   (Source: /ZendEngine2/ZEND_CHANGES)

-- 
  Sebastian Bergmann
  http://sebastian-bergmann.de/ http://phpOpenTracker.de/

  Did I help you? Consider a gift: http://wishlist.sebastian-bergmann.de/

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




Re: [Fwd: [PHP-DEV] Re: [Zend Engine 2] Re: [PHP-DEV] [RESENT][PATCH] Allow constants / expressions to be passed by reference]]

2002-05-29 Thread Jason T. Greene

Yes and as I said in my argument, this solves some of the problems but
does not solve a non-rightmost parameter being optional.

-Jason

On Wed, 2002-05-29 at 11:43, Sebastian Bergmann wrote:
   Hamster ate my mail? Resent, just in case.
 
 Sebastian Bergmann wrote:
  brad lafountain wrote:
  function foo($bar = null)
  {
  }
 
   This has already been fixed for the Zend Engine 2:
 
  * Parameters that are passed by reference to a function
may now have default values.
 
Example:
 
  ?php
  function my_function($var = null) {
   if ($var === null) {
   die('$var needs to have a value');
   }
  }
  ?
 
(Source: /ZendEngine2/ZEND_CHANGES)
 
 -- 
   Sebastian Bergmann
   http://sebastian-bergmann.de/ http://phpOpenTracker.de/
 
   Did I help you? Consider a gift: http://wishlist.sebastian-bergmann.de/
 
 -- 
 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-DEV] Re: [Zend Engine 2] RE: [PHP-DEV] Re: [Zend Engine 2] Re: [PHP-DEV][RESENT] [PATCH] Allow constants / expressions to be passed by reference]

2002-05-29 Thread Shane Caraveo

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:[EMAIL PROTECTED]]
Sent: mercredi 29 mai 2002 17:26
To: Stig S. Bakken; Jason T. Greene
Cc: [EMAIL PROTECTED]; [EMAIL PROTECTED]
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:

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.c23 Apr 2002 18:06:53 -  1.285
+++ zend_compile.c25 May 2002 06:45:21 -
@@ -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.c8 May 2002 18:43:19 -   1.341
+++ zend_execute.c25 May 2002 06:45:25 -
@@ -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

Re: [PHP-DEV] Re: [Zend Engine 2] Re: [PHP-DEV] [RESENT] [PATCH] Allow constants / expressions to be passed by reference]

2002-05-29 Thread Andi Gutmans

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.c23 Apr 2002 18:06:53 -  1.285
+++ zend_compile.c25 May 2002 06:45:21 -
@@ -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.c8 May 2002 18:43:19 -   1.341
+++ zend_execute.c25 May 2002 06:45:25 -
@@ -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 

Re: [PHP-DEV] Re: [Zend Engine 2] Re: [PHP-DEV] [RESENT] [PATCH]Allow constants / expressions to be passed by reference]

2002-05-29 Thread Jason T. Greene

On Wed, 2002-05-29 at 13:53, Andi Gutmans wrote:
 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.
Thanks, I did test this very thoroughly. However, due to its possible
far reaching effects, I would appreciate someone else taking their time
on a careful review.

I understand if it takes you awhile to get to it

-Jason

 Andi
 



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