note 56644 added to language.references.pass

From: Date: Sat, 10 Sep 2005 19:15:51 +0000
Subject: note 56644 added to language.references.pass
Groups: php.notes 
Request: Send a blank email to php-notes+get-94996@lists.php.net to get a copy of this message
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 ?> ---- Manual Page -- http://www.php.net/manual/en/language.references.pass.php Edit -- http://master.php.net/manage/user-notes.php?action=edit+56644 Delete: added to the manual -- http://master.php.net/manage/user-notes.php?action=delete+56644&report=yes&reason=added+to+the+manual Delete: bad code -- http://master.php.net/manage/user-notes.php?action=delete+56644&report=yes&reason=bad+code Delete: spam -- http://master.php.net/manage/user-notes.php?action=delete+56644&report=yes&reason=spam Delete: useless -- http://master.php.net/manage/user-notes.php?action=delete+56644&report=yes&reason=useless Delete: non-english -- http://master.php.net/manage/user-notes.php?action=delete+56644&report=yes&reason=non-english Delete: other reasons -- http://master.php.net/manage/user-notes.php?action=delete+56644&report=yes Reject -- http://master.php.net/manage/user-notes.php?action=reject+56644&report=yes Search -- http://master.php.net/manage/user-notes.php

« previous php.notes (#94996) next »