History | Log In     View a printable version of the current page.  
Issue Details (XML | Word | Printable)

Key: ZF-800
Type: Bug Bug
Status: Closed Closed
Resolution: Fixed
Priority: Major Major
Assignee: Gavin
Reporter: Gavin
Votes: 0
Watchers: 1
Operations

If you were logged in you would be able to see more operations.
Google issue summary
Zend Framework

After adding an array to a session namespace, adding elements to the array fails

Created: 25/Jan/07 10:18 PM   Updated: 31/Jul/07 01:36 PM
Component/s: Zend_Session
Affects Version/s: 0.7.0
Fix Version/s: 0.8.0

Time Tracking:
Not Specified

Issue Links:
Related
 

Resolution Date: 21/Feb/07 04:56 PM


 Description  « Hide
-------- Original Message --------
Subject: [fw-auth] Problem with Zend Session and setting arrays
Date: Thu, 18 Jan 2007 07:00:40 -0800 (PST)
From: Daniel Schwip. (Germany) <ds@ms-computerservice.com>
To: fw-auth@lists.zend.com

Hi there,
if i set a session property to an array and later add a new key, it won't be
set. I think it's because of the __set php implementation???


$session = new Zend_session();
$session->array = array();
$session->array['testKey'] = 1;
Zend::Dump($session->array, 'sessArray'); // testKey is not set
// My Current workaround
$session->array = array_merge($session->array, array('testKey' => 1));



 All   Comments   Work Log   Change History   FishEye   Crucible      Sort Order: Ascending order - Click to sort in descending order
Gavin - 26/Jan/07 10:50 AM
Oddly, I found setting additional keys in the array works, with only the first one "ignored" by PHP.
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


Gavin - 26/Jan/07 11:14 AM
The result differs for PHP 5.2, and the "trick" above no longer works. All keys added are "ignored" by PHP.

$ php -v
PHP 5.2.0 (cgi-fcgi) (built: Dec 19 2006 15:37:32)
Copyright (c) 1997-2006 The PHP Group
Zend Engine v2.2.0, Copyright (c) 1998-2006 Zend Technologies

gavin@IBM-F4F0A5528C1 ~/src/zftrunk/tests/Zend/Session
$ uname -a
CYGWIN_NT-5.1 IBM-F4F0A5528C1 1.5.22(0.156/4/2) 2006-11-13 17:01 i686 Cygwin

gavin@IBM-F4F0A5528C1 ~/src/zftrunk/tests/Zend/Session
$ svn update
At revision 3016.


Gavin - 29/Jan/07 04:27 PM
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-around

Do not modify an array, after assigning it to a session namespace key.


Gavin - 30/Jan/07 01:29 PM
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+):
http://bugs.php.net/bug.php?id=39449

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.


Gavin - 30/Jan/07 03:18 PM

Another Work-Around

$myNamespace = new Zend_Session_Namespace('mySpace');

// works, even for broken versions of PHP
$a = array(1,2,3);
$myNamespace->someArray = array( & $a ) ;
$a['foo'] = 'bar';

Stephen St. Martin - 21/Feb/07 04:25 PM
5.2.1 has been released, and i have confirmed the issue no longer exists, this could probably be closed.