#34193 [Opn->Bgs]: return new Object() in function returning reference.

From: Date: Fri, 19 Aug 2005 13:15:21 +0000
Subject: #34193 [Opn->Bgs]: return new Object() in function returning reference.
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-83817@lists.php.net to get a copy of this message
ID: 34193 Updated by: derick@php.net Reported By: benoit at bh-services dot net -Status: Open +Status: Bogus Bug Type: Scripting Engine problem Operating System: WIN32 XP SP2 PHP Version: 4.4.0 New Comment: Thank you for taking the time to write to us, but this is not a bug. Please double-check the documentation available at http://www.php.net/manual/ and the instructions on how to report a bug at http://bugs.php.net/how-to-report.php . Previous Comments: ------------------------------------------------------------------------ [2005-08-19 15:13:49] benoit at bh-services dot net Description: ------------ Hi all, I've read and searched all the bugs report about the famous "Only variable references should be returned by reference" Notice and I not yet found this case. This one in fact is very tricky, it happens when you have a function intended to return a reference on a variable, and in this one in some cases you want to return an object (In my case is to manage new Exception() objects to emulate the try/catch mechanism). So if you try to return directly new Object() in the function then you have a notice. This means new Object() does not return a reference (or is not considered as a reference on variable). By the way, you can do stuff like this : $obj = & new Object(); So that means here the new Object() is ok for references... So what is the rule here ? For me it's simply to allow the usage of references on new Object() calls because is very useful, and for me this not a bug to have reference on new object (which is infact the first reference an object/variable can have). Thanks for the team, and I hope this one will be fixed in the 4.4.1 ;) /Benoit Heinrich Reproduce code: --------------- <?php error_reporting(E_ALL); // very important. class Object() { } function &fct() { return new Object(); } $obj = & fct(); // will display the notice $obj = & new Object(); // this one no notice ?> will display: Notice: Only variable references should be returned by reference Expected result: ---------------- Have no notice at all when I use the E_ALL for reporting. Actual result: -------------- The famous Notice: Only variable references should be returned by reference. ------------------------------------------------------------------------ -- Edit this bug report at http://bugs.php.net/?id=34193&edit=1

« previous php.bugs (#83817) next »