Re: [PHP] Re: PHP5 and pass by reference bug.

2004-07-17 Thread Curt Zirzow
* Thus wrote Daevid Vincent:
 Yeah, I get what references are. The point is that when it was on the user
 to decide, they could do it. Now that PHP5 makes you put the  in the
 function declaration instead of the passing parameter, you don't know what
 the user is going to send. Therefore it renders the  in the function
 declaration a useless thing.
 
 I could have this function
 
   Function add ($a, $b)
   {
  return ($a + $b);
   }
 
 And as a user I could use it like so:
 
   $x = 5;
   $y = 10;
   add($x, $y);
 
 Or I could also use it like this:
 
   add(5,10);
 
 But since the function is now responsible in PHP5 to use the  [since
 passing add($x, $y); is now invalid],  it makes my function add basically
 useless.

The only time you should pass by reference is when you plan on
modifiying that variable and the caller is going to get a modified
version back:

function foo($modify_me) {
  $modify_me = 'another value';
}
foo($var);
// var contains now 'another value'


Otherwise, always declare your functions as normal variables.

Or for your example, you provided, that would mean that in your
original code you had called your functions as:

 add(5, 10);

Which is obviosly wrong, so going that route wont really work.


If you're concerned about memory usage, like why do I need to
duplicate memory if I'm just passing variables that will just
simply be read. Well, PHP takes that pretty much into
consideration. And the only time a duplicate is created is when you
modify the variable.

If for example you have:
  $var = 'a really long string';

And you assign that variable to something else:

  $var2 = $var;

PHP doesn't allocate all the  memory  of var for that var2 until
you try to modify the $var2. So not until you do something like:

  $var2 .= 'some more text';

PHP then will make a copy of the original $var, and then make
modifications.


The same principle applies to function parameters.


Curt
-- 
First, let me assure you that this is not one of those shady pyramid schemes
you've been hearing about.  No, sir.  Our model is the trapezoid!

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



[PHP] Re: PHP5 and pass by reference bug.

2004-07-16 Thread Red Wingate
Maybe you recheck the dokumentation on what exactly referenzes are. Do 
you expect the function to alter the string something here and every-
time you later print the string within your script you get the altered one?

ONLY variables can be passed by referenze !
 -- red
Daevid Vincent wrote:
So, I'm getting all these errors/warnings in PHP5 now saying that I have to
put the  on the function and not in the passing (which sorta makes sense
and puts the burden on the function rather than the user, which I like too).
So I spend the time to go and fix several thousand lines of code.
Then I start to see these other errors...
Maybe I'm missing something, but this seems like a glaring bug in passing by
reference that nobody caught...
say you have 

	function foo($bar) 
	{
	}

well that works great as long as you use it like
foo($x);
but if you try 

foo(something here);
Or
foo( array('a','b','c') );
it shits the bed. :-(
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[PHP] Re: PHP5 and pass by reference bug.

2004-07-16 Thread Red Wingate
Maybe you recheck the dokumentation on what exactly referenzes are. Do 
you expect the function to alter the string something here and every-
time you later print the string within your script you get the altered one?

ONLY variables can be passed by referenze !
 -- red
Daevid Vincent wrote:
So, I'm getting all these errors/warnings in PHP5 now saying that I have to
put the  on the function and not in the passing (which sorta makes sense
and puts the burden on the function rather than the user, which I like too).
So I spend the time to go and fix several thousand lines of code.
Then I start to see these other errors...
Maybe I'm missing something, but this seems like a glaring bug in passing by
reference that nobody caught...
say you have 

	function foo($bar) 
	{
	}

well that works great as long as you use it like
foo($x);
but if you try 

foo(something here);
Or
foo( array('a','b','c') );
it shits the bed. :-(
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


RE: [PHP] Re: PHP5 and pass by reference bug.

2004-07-16 Thread Daevid Vincent
Yeah, I get what references are. The point is that when it was on the user
to decide, they could do it. Now that PHP5 makes you put the  in the
function declaration instead of the passing parameter, you don't know what
the user is going to send. Therefore it renders the  in the function
declaration a useless thing.

I could have this function

Function add ($a, $b)
{
   return ($a + $b);
}

And as a user I could use it like so:

$x = 5;
$y = 10;
add($x, $y);

Or I could also use it like this:

add(5,10);

But since the function is now responsible in PHP5 to use the  [since
passing add($x, $y); is now invalid],  it makes my function add basically
useless.


 -Original Message-
 From: Red Wingate [mailto:[EMAIL PROTECTED] 
 Sent: Friday, July 16, 2004 5:35 PM
 To: [EMAIL PROTECTED]
 Subject: [PHP] Re: PHP5 and pass by reference bug.
 
 Maybe you recheck the dokumentation on what exactly 
 referenzes are. Do 
 you expect the function to alter the string something here 
 and every-
 time you later print the string within your script you get 
 the altered one?
 
 ONLY variables can be passed by referenze !
 
   -- red
 
 Daevid Vincent wrote:
  So, I'm getting all these errors/warnings in PHP5 now 
 saying that I have to
  put the  on the function and not in the passing (which 
 sorta makes sense
  and puts the burden on the function rather than the user, 
 which I like too).
  So I spend the time to go and fix several thousand lines of code.
  
  Then I start to see these other errors...
  
  Maybe I'm missing something, but this seems like a glaring 
 bug in passing by
  reference that nobody caught...
  
  say you have 
  
  function foo($bar) 
  {
  }
  
  well that works great as long as you use it like
  
  foo($x);
  
  but if you try 
  
  foo(something here);
  Or
  foo( array('a','b','c') );
  
  it shits the bed. :-(
 
 -- 
 PHP General Mailing List (http://www.php.net/)
 To unsubscribe, visit: http://www.php.net/unsub.php
 

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



Re: [PHP] Re: PHP5 and pass by reference bug.

2004-07-16 Thread Justin Patrin
But that function doesn't need to pass by reference. If you have a
function that has a parameter that is passed by ref, it should always
be a variable that is passed in. You should only be using pass by ref
when the function changes the value and it simply doesn't make sense
to change a constant.

On Fri, 16 Jul 2004 18:03:08 -0700, Daevid Vincent [EMAIL PROTECTED] wrote:
 Yeah, I get what references are. The point is that when it was on the user
 to decide, they could do it. Now that PHP5 makes you put the  in the
 function declaration instead of the passing parameter, you don't know what
 the user is going to send. Therefore it renders the  in the function
 declaration a useless thing.
 
 I could have this function
 
 Function add ($a, $b)
 {
return ($a + $b);
 }
 
 And as a user I could use it like so:
 
 $x = 5;
 $y = 10;
 add($x, $y);
 
 Or I could also use it like this:
 
 add(5,10);
 
 But since the function is now responsible in PHP5 to use the  [since
 passing add($x, $y); is now invalid],  it makes my function add basically
 useless.
 
 
 
 
  -Original Message-
  From: Red Wingate [mailto:[EMAIL PROTECTED]
  Sent: Friday, July 16, 2004 5:35 PM
  To: [EMAIL PROTECTED]
  Subject: [PHP] Re: PHP5 and pass by reference bug.
 
  Maybe you recheck the dokumentation on what exactly
  referenzes are. Do
  you expect the function to alter the string something here
  and every-
  time you later print the string within your script you get
  the altered one?
 
  ONLY variables can be passed by referenze !
 
-- red
 
  Daevid Vincent wrote:
   So, I'm getting all these errors/warnings in PHP5 now
  saying that I have to
   put the  on the function and not in the passing (which
  sorta makes sense
   and puts the burden on the function rather than the user,
  which I like too).
   So I spend the time to go and fix several thousand lines of code.
  
   Then I start to see these other errors...
  
   Maybe I'm missing something, but this seems like a glaring
  bug in passing by
   reference that nobody caught...
  
   say you have
  
   function foo($bar)
   {
   }
  
   well that works great as long as you use it like
  
   foo($x);
  
   but if you try
  
   foo(something here);
   Or
   foo( array('a','b','c') );
  
   it shits the bed. :-(
 
  --
  PHP General Mailing List (http://www.php.net/)
  To unsubscribe, visit: http://www.php.net/unsub.php
 
 
 --
 PHP General Mailing List (http://www.php.net/)
 To unsubscribe, visit: http://www.php.net/unsub.php
 
 
 !DSPAM:40f878c7129391185556252!
 
 


-- 
DB_DataObject_FormBuilder - The database at your fingertips
http://pear.php.net/package/DB_DataObject_FormBuilder

paperCrane --Justin Patrin--

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