note 56644 deleted from language.references.pass by danbrown

From: Date: Thu, 28 Jan 2010 13:20:07 +0000
Subject: note 56644 deleted from language.references.pass by danbrown
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-165421@lists.php.net to get a copy of this message
Note Submitter: andrzej dot martynowicz at gmail dot com ---- As bobbykjack at hotmail dot com noticed 'reference parameters cannot be assigned a default value'. Yes, but I've found a workaround to this problem. The idea is to create object that will hold the reference and pass the instance of this 'Reference object' as a desired parameter (which is not preceded by & operator). One can then extract the refernce from passed 'Reference object'. See below how this works.. <? class Ref { var $ref; function Ref( &$reference ) { $this->ref = &$reference; } } function myFunc( $param = null ) { $param = &$param->ref; // notice & operator here $param = 'php'; } $foo = 'foo'; myFunc( new Ref( $foo )); echo $foo; // outputs: php ?>

« previous php.notes (#165421) next »