Re: Argument passed by reference?
| From: | Chris | Date: | Tue, 11 Apr 2006 01:56:27 +0000 |
| Subject: | Re: Argument passed by reference? | ||
| References: | 1 2 3 4 5 6 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-233719@lists.php.net to get a copy of this message | ||
tedd wrote:
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/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.phpChris: 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?).