Re: [PHP] Argument passed by reference?

2006-04-10 Thread Joe Henry
On Friday 07 April 2006 5:06 pm, tedd wrote:
 At 1:52 PM -0500 4/6/06, Chris Boget wrote:
 The way I understand it, pass by reference in php is determined in
 the function definition and not the function call. Something like:
 
 You used to be able to pass by reference at run time.  But I see that is
 no longer allowed... :|  So I guess that makes my question moot.
 
 Thanks for your help.
 
 thnx,
 Chris

 Chris:

 Please forgive my ignorance, but when did that happen?

 tedd
 --
 ---
- http://sperling.com

I'm not sure when this happened. I'm fairly new to php, myself. Maybe someone 
else could answer that?
-- 
Joe Henry
www.celebrityaccess.com
[EMAIL PROTECTED]

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



Re: [PHP] Argument passed by reference?

2006-04-10 Thread Chris

Joe Henry wrote:

On Friday 07 April 2006 5:06 pm, tedd wrote:


At 1:52 PM -0500 4/6/06, Chris Boget wrote:


The way I understand it, pass by reference in php is determined in
the function definition and not the function call. Something like:


You used to be able to pass by reference at run time.  But I see that is
no longer allowed... :|  So I guess that makes my question moot.

Thanks for your help.

thnx,
Chris


Chris:

Please forgive my ignorance, but when did that happen?


I'm not sure when this happened. I'm fairly new to php, myself. Maybe someone 
else could answer that?



It's not that it's not allowed, it's that it should be done differently. 
You should make the function accept a reference in the definition, not 
pass in a reference to the function.


The manual page has a good, simple example on what to do.

http://www.php.net/manual/en/language.references.pass.php

--
Postgresql  php tutorials
http://www.designmagick.com/

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



Re: [PHP] Argument passed by reference?

2006-04-10 Thread tedd
It's not that it's not allowed, it's that it should be done 
differently. You should make the function accept a reference in the 
definition, not pass in a reference to the function.


The manual page has a good, simple example on what to do.

http://www.php.net/manual/en/language.references.pass.php


Chris:

Interesting. One would think (at least I do) it should be the other way around.

Using the example given at the link above:

?php
function foo($var)
{
   $var++;
}

$a=5;
foo($a);
// $a is 6 here
?

We have one function that works one way.

?php
function foo($var)
{
   $var++;
}

$a=5;
foo($a);
// $a is 6 here
?

However, doing it this way, the function can serve two purposes. I 
can send it a reference or I could send it a value. I know that in 
this function a value doesn't do anything, but it could if the 
function was different.


Plus, in the first function, I can't send it a reference (i.e., a 
reference to a reference?).


What's short reasoning for this being recommended this way? What am I 
not seeing?


tedd
--

http://sperling.com

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



Re: [PHP] Argument passed by reference?

2006-04-10 Thread Chris

tedd wrote:
It's not that it's not allowed, it's that it should be done 
differently. You should make the function accept a reference in the 
definition, not pass in a reference to the function.


The manual page has a good, simple example on what to do.

http://www.php.net/manual/en/language.references.pass.php



Chris:

Interesting. One would think (at least I do) it should be the other way 
around.


Using the example given at the link above:

?php
function foo($var)
{
   $var++;
}

$a=5;
foo($a);
// $a is 6 here
?

We have one function that works one way.

?php
function foo($var)
{
   $var++;
}

$a=5;
foo($a);
// $a is 6 here
?

However, doing it this way, the function can serve two purposes. I can 
send it a reference or I could send it a value. I know that in this 
function a value doesn't do anything, but it could if the function was 
different.


Plus, in the first function, I can't send it a reference (i.e., a 
reference to a reference?).


I'd guess it's to simplify things.

Having been involved in a big cms that used references all over the 
place (everything was OO), it was extremely hard to find / track down 
where they should be and where they were missing - which caused memory 
blow-outs where they were not used, and segfault crashes where they were 
incorrectly used.


If they were all in the function definitions, I don't have to worry 
about that particular problem.


However, it's something the developers would have to give a definitive 
answer on.


--
Postgresql  php tutorials
http://www.designmagick.com/

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



Re: [PHP] Argument passed by reference?

2006-04-07 Thread tedd

At 1:24 PM -0500 4/6/06, Chris Boget wrote:
Is there a way to test to see if a function argument was passed by 
reference instead of by value?


thnx,
Chris


Chris:

As I am sure you know, passing by reference is simply passing the 
memory address of the variable to a function instead of it's value. 
If the receiving function does something to the variable at that 
address, then the value at that address is changed. You can test this 
by simply checking the value before and after it's returned from the 
function.


For example, the following just passes the memory address of variable 
$a to a function. After which, the function alters the variable at 
that memory address, but doe not return a value. But, echoing the 
variable after the function call shows that the variable has indeed 
been altered.


?php
$a = 10;
echo($a br/);
ref($a);
echo($a);
?


?php
function ref($a)
{
$a--;
}

?

HTH's

tedd

--

http://sperling.com

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



Re: [PHP] Argument passed by reference?

2006-04-07 Thread tedd

At 1:52 PM -0500 4/6/06, Chris Boget wrote:
The way I understand it, pass by reference in php is determined in 
the function definition and not the function call. Something like:


You used to be able to pass by reference at run time.  But I see that is
no longer allowed... :|  So I guess that makes my question moot.

Thanks for your help.

thnx,
Chris


Chris:

Please forgive my ignorance, but when did that happen?

tedd
--

http://sperling.com

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



Re: [PHP] Argument passed by reference?

2006-04-06 Thread Joe Henry
On Thursday 06 April 2006 12:24 pm, Chris Boget wrote:
 Is there a way to test to see if a function argument was passed by
 reference instead of by value?

 thnx,
 Chris

The way I understand it, pass by reference in php is determined in the 
function definition and not the function call. Something like:

function foo ($bar) {
...
}

Here's a link to that section of the php manual:

http://us3.php.net/manual/en/language.references.pass.php

Hope that helps.
-- 
Joe Henry
www.celebrityaccess.com
[EMAIL PROTECTED]

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



Re: [PHP] Argument passed by reference?

2006-04-06 Thread Chris Boget
The way I understand it, pass by reference in php is determined in the 
function definition and not the function call. Something like:


You used to be able to pass by reference at run time.  But I see that is
no longer allowed... :|  So I guess that makes my question moot.

Thanks for your help.

thnx,
Chris

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