note 70212 added to language.references.pass

From: Date: Fri, 06 Oct 2006 21:37:57 +0000
Subject: note 70212 added to language.references.pass
Groups: php.notes 
Request: Send a blank email to php-notes+get-118158@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/70212 Del: integrated -- https://master.php.net/note/delete/70212/integrated Del: useless -- https://master.php.net/note/delete/70212/useless Del: bad code -- https://master.php.net/note/delete/70212/bad+code Del: spam -- https://master.php.net/note/delete/70212/spam Del: non-english -- https://master.php.net/note/delete/70212/non-english Del: in docs -- https://master.php.net/note/delete/70212/in+docs Del: other reasons-- https://master.php.net/note/delete/70212 Reject -- https://master.php.net/note/reject/70212 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#118158) next »