Re: function by reference

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



At 7:31 PM -0700 4/10/06, Ray Hauge wrote:
 >
 I believe you're thinking more of the C++ style of returning by reference.
 This article should help explain how references work, and how to return
 references... most specifically check the "Returning References" section.

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

nevermind... I what I read and what was actually written seem to have been two
entirely different things ;)  Still good info though.

--
Ray Hauge

Ray:

It was an interesting read -- but, I found it, and the comments, confusing.

The difference I was able to get was I know if you display a C pointer, would will see a memory address -- if you display a PHP reference, you will see the value. As such, one is a memory address and the other is a symbol table alias -- but they still seem to work the same. I haven't seen a working difference yet.

Additionally, what I don't get is this:

<?php
	$a = 10;
	echo("$a <br/>");
	ref1(&$a);
	echo("$a <br/>");

	$a = 10;
	echo("$a <br/>");
	ref2($a);
	echo("$a <br/>");

	$a = 10;
	echo("$a <br/>");
	ref3($a);
	echo("$a <br/>");

?>


<?php
	function ref1($a)
		{
		$a--;
		}

?>

<?php
	function ref2(&$a)
		{
		$a--;
		}

?>

<?php
	function &ref3($a)
		{
		$a--;
		}

?>

The first two functions work as I would expect. The last one is shown in the documentation, but doesn't work as I expected. There doesn't appear to be any difference between ref1 and ref3 -- so what's with the "ampersand" in &ref3? What is an ampersand supposed to mean/do when it precedes a function?

Thanks.

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

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


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux