|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
[2005-08-19 15:15 UTC] derick@php.net
|
|||||||||||||||||||||||||||
Copyright © 2001-2026 The PHP GroupAll rights reserved. |
Last updated: Wed Oct 07 22:00:01 2026 UTC |
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.