I know that this is highly discouraged in the PHP community, but I'm afraid I have come up with a scenario where you have no choice but to globalize an autoglobal, whether you like it or not, and I welcome arguments to the contrary.
I've done this successfully in PHP versions 4.1.2, 4.3.2 and 4.3.6, always with register_globals off, performing this action within a class method:
class Foo {
function Foo() {}
function doStuff() {
if (!$_REQUEST['myVar']) {
$_REQUEST['myVar'] = $myVar;
global $_REQUEST;
}
}
}
$foo =& new Foo();
$foo->doStuff();
$foo = null;
With the global line:
Array (... [myvar] => 'hello world', [myOtherVar] => 'foo' ...)
Without the global line, this is what $_REQUEST will look like:
Array (...[myOtherVar] => 'foo'...)
There is no $REQUEST element named 'myVar' upon existing the class method, though $REQUEST is an autoglobal it retains its original elemental order w/o modification as performed in the class method. But if I put the global line back into the class method, $_REQUEST retains the 'myVar' element upon method exit and all is well.
This works in three different versions of PHP (4.1.2, 4.3.2, and 4.3.6) and is guaranteed only to perform properly within these versions if register_globals is off via php.ini or is turned off locally via ini_set().
So, there you have it.. globalizing an autoglobal appears to not such a bad idea after all, just like locally turning off register_globals at application level is also a doable option as well.
Phil