#33352 [Opn]: returning references document says that class methods return reference is wrong

From: Date: Wed, 15 Jun 2005 14:11:27 +0000
Subject: #33352 [Opn]: returning references document says that class methods return reference is wrong
References: 1  Groups: php.doc 
Request: Send a blank email to phpdoc+get-969368623@lists.php.net to get a copy of this message
ID: 33352 Updated by: vrana@php.net Reported By: cmoore at iyd dot com Status: Open Bug Type: Documentation problem Operating System: Gentoo Linux PHP Version: Irrelevant New Comment: Fur further reference: it was added for the sake of bug #29877. Previous Comments: ------------------------------------------------------------------------ [2005-06-15 15:58:23] cmoore at iyd dot com Description: ------------ On the document page: http://us2.php.net/manual/en/language.references.return.php "& by function definition is optional in class methods." Reproduce code: --------------- <? class reftest { var $var = "original"; function by_copy() { return $this->var; } } print "By copy:\n"; $t = new reftest; var_dump($t); $c =& $t->by_copy(); $c = "copy"; var_dump($t); Expected result: ---------------- According to docs, $c should be a reference to the class variable. $t->c should have the value "copy" in the output from the last var_dump. When an ampersand is prefixed on the function by_copy(), it works as expected. Actual result: -------------- as demonstrated by the above code, a copy is returned. ------------------------------------------------------------------------ -- Edit this bug report at http://bugs.php.net/?id=33352&edit=1

« previous php.doc (#969368623) next »