#33679 [NEW]: Function returning reference via "return new" or delegating
| From: | mikael at chl dot chalmers dot se | Date: | Wed, 13 Jul 2005 13:27:45 +0000 |
| Subject: | #33679 [NEW]: Function returning reference via "return new" or delegating | ||
| Groups: | php.bugs | ||
| Request: | Send a blank email to php-bugs+get-81802@lists.php.net to get a copy of this message | ||
From: mikael at chl dot chalmers dot se
Operating system: Linux
PHP version: 4.4.0
PHP Bug Type: Class/Object related
Bug description: Function returning reference via "return new" or delegating
Description:
------------
Would have added a comment to #33558
When calling a function that returns a reference using "return new
SomeClass()" (or via delegate to another function that returns a
reference) the "Notice: Only variable references should be returned by
reference" is triggered.
However; when a reference to $this is set in the $GLOBALS array in the
contructor the notice is not triggered and both $a and $b refer to the
same object as shown in the example.
Se also related #24687 and #26439 that gives weight to the desired
behaviour of "return new" and "return deletegatingFactoryMethod()" really
returning references
"return null" being valid from a return-by-reference function is also
desired
Reproduce code:
---------------
class FooBar {
function FooBar() {
// Enabling this line will prevent the E_NOTICE
//$GLOBALS['a'] =& $this;
}
}
function &factory() {
return new FooBar();
}
function &deletegatingFactoryMethod() {
return factory();
}
function &returnNull() {
return null;
}
deletegatingFactoryMethod();
returnNull();
$b =& factory();
$b->foo = 'bar';
//var_dump($GLOBALS['a']);
var_dump($b);
Expected result:
----------------
No notices
Actual result:
--------------
The notice is triggered 4 times
--
Edit bug report at http://bugs.php.net/?id=33679&edit=1
--
Try a CVS snapshot (php4): http://bugs.php.net/fix.php?id=33679&r=trysnapshot4
Try a CVS snapshot (php5.0): http://bugs.php.net/fix.php?id=33679&r=trysnapshot50
Try a CVS snapshot (php5.1): http://bugs.php.net/fix.php?id=33679&r=trysnapshot51
Fixed in CVS: http://bugs.php.net/fix.php?id=33679&r=fixedcvs
Fixed in release: http://bugs.php.net/fix.php?id=33679&r=alreadyfixed
Need backtrace: http://bugs.php.net/fix.php?id=33679&r=needtrace
Need Reproduce Script: http://bugs.php.net/fix.php?id=33679&r=needscript
Try newer version: http://bugs.php.net/fix.php?id=33679&r=oldversion
Not developer issue: http://bugs.php.net/fix.php?id=33679&r=support
Expected behavior: http://bugs.php.net/fix.php?id=33679&r=notwrong
Not enough info: http://bugs.php.net/fix.php?id=33679&r=notenoughinfo
Submitted twice: http://bugs.php.net/fix.php?id=33679&r=submittedtwice
register_globals: http://bugs.php.net/fix.php?id=33679&r=globals
PHP 3 support discontinued: http://bugs.php.net/fix.php?id=33679&r=php3
Daylight Savings: http://bugs.php.net/fix.php?id=33679&r=dst
IIS Stability: http://bugs.php.net/fix.php?id=33679&r=isapi
Install GNU Sed: http://bugs.php.net/fix.php?id=33679&r=gnused
Floating point limitations: http://bugs.php.net/fix.php?id=33679&r=float
No Zend Extensions: http://bugs.php.net/fix.php?id=33679&r=nozend
MySQL Configuration Error: http://bugs.php.net/fix.php?id=33679&r=mysqlcfg