#34193 [NEW]: return new Object() in function returning reference.
| From: | benoit at bh-services dot net | Date: | Fri, 19 Aug 2005 13:13:51 +0000 |
| Subject: | #34193 [NEW]: return new Object() in function returning reference. | ||
| Groups: | php.bugs | ||
| Request: | Send a blank email to php-bugs+get-83816@lists.php.net to get a copy of this message | ||
From: benoit at bh-services dot net
Operating system: WIN32 XP SP2
PHP version: 4.4.0
PHP Bug Type: Scripting Engine problem
Bug description: return new Object() in function returning reference.
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 bug report at http://bugs.php.net/?id=34193&edit=1
--
Try a CVS snapshot (php4): http://bugs.php.net/fix.php?id=34193&r=trysnapshot4
Try a CVS snapshot (php5.0): http://bugs.php.net/fix.php?id=34193&r=trysnapshot50
Try a CVS snapshot (php5.1): http://bugs.php.net/fix.php?id=34193&r=trysnapshot51
Fixed in CVS: http://bugs.php.net/fix.php?id=34193&r=fixedcvs
Fixed in release: http://bugs.php.net/fix.php?id=34193&r=alreadyfixed
Need backtrace: http://bugs.php.net/fix.php?id=34193&r=needtrace
Need Reproduce Script: http://bugs.php.net/fix.php?id=34193&r=needscript
Try newer version: http://bugs.php.net/fix.php?id=34193&r=oldversion
Not developer issue: http://bugs.php.net/fix.php?id=34193&r=support
Expected behavior: http://bugs.php.net/fix.php?id=34193&r=notwrong
Not enough info: http://bugs.php.net/fix.php?id=34193&r=notenoughinfo
Submitted twice: http://bugs.php.net/fix.php?id=34193&r=submittedtwice
register_globals: http://bugs.php.net/fix.php?id=34193&r=globals
PHP 3 support discontinued: http://bugs.php.net/fix.php?id=34193&r=php3
Daylight Savings: http://bugs.php.net/fix.php?id=34193&r=dst
IIS Stability: http://bugs.php.net/fix.php?id=34193&r=isapi
Install GNU Sed: http://bugs.php.net/fix.php?id=34193&r=gnused
Floating point limitations: http://bugs.php.net/fix.php?id=34193&r=float
No Zend Extensions: http://bugs.php.net/fix.php?id=34193&r=nozend
MySQL Configuration Error: http://bugs.php.net/fix.php?id=34193&r=mysqlcfg