note 69732 added to language.references.pass
| From: | tachdaun at gmail dot com | Date: | Mon, 18 Sep 2006 15:48:46 +0000 |
| Subject: | note 69732 added to language.references.pass | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-117293@lists.php.net to get a copy of this message | ||
There is actually a not-so-clean way to have default values for reference arguments
<?php
function hello( &$arg )
{
if( ! isset( $arg ) )
$arg = "A default value\n";
print $arg;
}
@hello();
hello( $var = "some value\n" );
?>
This would normally issue a Missing argument Warning, but if you disable warnings or use @, it
doesn't bother.
Unlike one could expect, isset( $arg ) doesn't really check if the argument is set, but it
checks if the calling variable in the caller scope is set.
The code will output:
A default value
some value
----
Server IP: 201.216.232.3
Probable Submitter: 200.114.166.165
----
Manual Page -- http://www.php.net/manual/en/language.references.pass.php
Edit -- https://master.php.net/note/edit/69732
Del: integrated -- https://master.php.net/note/delete/69732/integrated
Del: useless -- https://master.php.net/note/delete/69732/useless
Del: bad code -- https://master.php.net/note/delete/69732/bad+code
Del: spam -- https://master.php.net/note/delete/69732/spam
Del: non-english -- https://master.php.net/note/delete/69732/non-english
Del: in docs -- https://master.php.net/note/delete/69732/in+docs
Del: other reasons-- https://master.php.net/note/delete/69732
Reject -- https://master.php.net/note/reject/69732
Search -- https://master.php.net/manage/user-notes.php