note 69732 deleted from language.references.pass by colder

From: Date: Mon, 18 Sep 2006 17:24:33 +0000
Subject: note 69732 deleted from language.references.pass by colder
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-117294@lists.php.net to get a copy of this message
Note Submitter: tachdaun at gmail dot com Reason: bad code ---- 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

« previous php.notes (#117294) next »