note 70185 added to language.references.pass
| From: | TrainBoy at osu1 dot php dot net | Date: | Fri, 06 Oct 2006 05:35:06 +0000 |
| Subject: | note 70185 added to language.references.pass | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-118113@lists.php.net to get a copy of this message | ||
Be nice to put the argument about whether reference parameters can have default values or not to
rest.
First, a little reminder from the section on function arguments, "The default value must be a
constant expression, not (for example) a variable, a class member or a function call".
This means that you can't assign a default value that references another variable, to the
argument, but you should be able to assign a constant such as NULL.
Having said that, the following code works pretty much as expected in both PHP 5.1.4 and 5.1.2:
function foo($Inv, &$Ptr=NULL)
{
echo "In foo, Inv = ".$Inv.", Ptr = ".$Ptr."<br>\n";
if (isset($Ptr)) $Ptr = "set";
}
$Val = "unset";
foo(1);
echo "Val = ".$Val."<br>\n"; // outputs "unset"
foo(2, $Val);
echo "Val = ".$Val."<br>\n"; // outputs "set"
However PHP 4.2.2 is a whole 'nother story. The function prototype gets a parse error right at
the equal sign.
So it would appear that both camps are right, depending on which version of PHP you're using.
If you can control which one you run under and can pick one the V5 versions, it looks like
you're in good shape. If you have one of the V4 versions, you're probably not a happy
camper.
----
Server IP: 64.71.164.2
Probable Submitter: 141.154.127.218
----
Manual Page -- http://www.php.net/manual/en/language.references.pass.php
Edit -- https://master.php.net/note/edit/70185
Del: integrated -- https://master.php.net/note/delete/70185/integrated
Del: useless -- https://master.php.net/note/delete/70185/useless
Del: bad code -- https://master.php.net/note/delete/70185/bad+code
Del: spam -- https://master.php.net/note/delete/70185/spam
Del: non-english -- https://master.php.net/note/delete/70185/non-english
Del: in docs -- https://master.php.net/note/delete/70185/in+docs
Del: other reasons-- https://master.php.net/note/delete/70185
Reject -- https://master.php.net/note/reject/70185
Search -- https://master.php.net/manage/user-notes.php