Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:5439 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 45087 invoked by uid 1010); 13 Nov 2003 18:39:11 -0000 Delivered-To: ezmlm-scan-internals@lists.php.net Delivered-To: ezmlm-internals@lists.php.net Received: (qmail 44948 invoked from network); 13 Nov 2003 18:39:10 -0000 Received: from unknown (HELO molly.0x539.de) (217.28.101.185) by pb1.pair.com with SMTP; 13 Nov 2003 18:39:10 -0000 Received: from pd9e55c1d.dip.t-dialin.net ([217.229.92.29] helo=leetspeak.org) by molly.0x539.de with asmtp (Exim 4.14) id 1AKMJe-0002wh-Ah for internals@lists.php.net; Thu, 13 Nov 2003 19:35:38 +0100 Message-ID: <3FB3CFD5.70507@leetspeak.org> Date: Thu, 13 Nov 2003 19:39:17 +0100 User-Agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.5) Gecko/20031014 Thunderbird/0.3 X-Accept-Language: en-us, en MIME-Version: 1.0 To: internals@lists.php.net References: <1068703990.3fb320f6975fb@www.3gstech.com> In-Reply-To: <1068703990.3fb320f6975fb@www.3gstech.com> Content-Type: text/plain; charset=us-ascii; format=flowed Content-Transfer-Encoding: 7bit Subject: Re: [PHP-DEV] php5 method return reference error? From: cm@leetspeak.org (Michael Walter) Not sure I'm missing something, but I fail to see the problem: Doesn't PHP 5 use object references anyway? So function pla() { return new Foo(); } would return a reference anyway, instead of copying the object itself over? So just removing & should fix the problem, as long as you're dealing with objects. Cheers, Michael Walter A. Boring IV wrote: > Howdy, > I'm playing with php5 (from cvs), and came accross a strange error > that doesn't happen with php4. Maybe someone can shed some light on > this for me? > > I get the error > "Fatal error: Only variables or references can be returned by reference > in /home/waboring/devel/html/test.php on line 11" > > Here is the php code > > > class foo { > var $test = 0; > } > > class bar { > function &get() { > //both of these fail > //return new foo; > return $this->_buildOBJ(); > } > > function &_buildOBJ() { > $obj = new foo(); > $obj->test = 'worked'; > return $obj; > } > } > > $bar = new bar; > $foo = $bar->get(); > echo $foo->test; > ?> > > This doesn't happen in php4. > This seems to go away if I change the bar::get() method to > > function &get() { > $obj =& $this->_buildOBJ(); > return $obj; > } > > > This seems like a bug to me, since both cases the return value is a > reference of an object? > > Thanks Walt >