|
|
|
The result differs for PHP 5.2, and the "trick" above no longer works. All keys added are "ignored" by PHP.
$ php -v gavin@IBM-F4F0A5528C1 ~/src/zftrunk/tests/Zend/Session gavin@IBM-F4F0A5528C1 ~/src/zftrunk/tests/Zend/Session The following code produces inconsistent results on versions of PHP prior to PHP 5.2.1. Tests with 5.2.1RC4 seem to show the problem has been fixed with magic methods returning by reference.
<?php
session_start();
$_SESSION['anArray'] = array('a', 'b', 'c');
echo "\n\$_SESSION = ";
print_r($_SESSION);
class TestSessionRef
{
public function &__get($name)
{
echo "\nReturning \$_SESSION[$name] by reference\n";
return $_SESSION[$name];
}
}
$test = new TestSessionRef();
$test->anArray['foo'] = 'bar';
echo "\n\$test->anArray = ";
print_r($test->anArray);
echo "\n\$a = ";
$a = & $test->anArray;
$a['bee'] = 'honey';
print_r($a);
echo "\n\$_SESSION = ";
print_r($_SESSION);
Work-aroundDo not modify an array, after assigning it to a session namespace key. http://bugs.php.net/bug.php?id=36214
The new Zend_Session unit test passes with PHP 5.2.1RC4 (and hopefully will continue to pass with PHP 5.2.1+): If no further problems are found, after PHP 5.2.1 is released, then I will close this issue. Everyone using an earlier version of PHP should use the workaround above. 5.2.1 has been released, and i have confirmed the issue no longer exists, this could probably be closed.
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
The problem certainly appears related to PHP and not Zend_Session.
Thus, a temporary workaround for the code above:
$session->array['dummy''] = true; $session->array['testkey'] = 1;$ php -v
PHP 5.1.6 (cgi-fcgi) (built: Oct 24 2006 19:38:28)
Copyright (c) 1997-2006 The PHP Group
Zend Engine v2.1.0, Copyright (c) 1998-2006 Zend Technologies
$ svn update
uname At revision 3015.
$ uname -a
Linux sandbox.zend.com 2.6.9-34.EL #1 Fri Feb 24 16:44:51 EST 2006 i686 i686 i386 GNU/Linux