|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
[2005-07-13 19:03 UTC] sniper@php.net
|
|||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Fri Dec 05 20:00:01 2025 UTC |
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