Skip to content
This repository has been archived by the owner on Jan 31, 2020. It is now read-only.

Commit

Permalink
Merge branch 'hotfix/102'
Browse files Browse the repository at this point in the history
Close #102
Fixes #81
  • Loading branch information
weierophinney committed Jan 31, 2018
2 parents dc2c46a + 8ef1a57 commit 9338f1a
Show file tree
Hide file tree
Showing 4 changed files with 98 additions and 2 deletions.
8 changes: 7 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

All notable changes to this project will be documented in this file, in reverse chronological order by release.

## 2.8.4 - TBD
## 2.8.4 - 2018-01-31

### Added

Expand Down Expand Up @@ -34,6 +34,12 @@ All notable changes to this project will be documented in this file, in reverse
case whereby if the special `__ZF` session value is a non-array value,
initializing the session would result in errors.

- [#102](https://github.com/zendframework/zend-session/pull/102) fixes an issue
introduced with 2.8.0 with `AbstractContainer::offsetGet`. Starting in 2.8.0,
if the provided `$key` did not exist, the method would raise an error
regarding an invalid variable reference; this release provides a fix that
resolves that issue.

## 2.8.3 - 2017-12-01

### Added
Expand Down
7 changes: 6 additions & 1 deletion src/AbstractContainer.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,11 @@ abstract class AbstractContainer extends ArrayObject
*/
protected static $defaultManager;

/**
* Default value to return by reference from offsetGet
*/
private $defaultValue = null;

/**
* Constructor
*
Expand Down Expand Up @@ -425,7 +430,7 @@ public function offsetExists($key)
public function &offsetGet($key)
{
if (! $this->offsetExists($key)) {
return;
return $this->defaultValue;
}
$storage = $this->getStorage();
$name = $this->getName();
Expand Down
68 changes: 68 additions & 0 deletions test/AbstractContainerTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
<?php
/**
* Zend Framework (http://framework.zend.com/)
*
* @link http://github.com/zendframework/zf2 for the canonical source repository
* @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/

namespace ZendTest\Session;

use PHPUnit\Framework\TestCase;
use Zend\Session\Container;
use Zend\Session\Config\StandardConfig;
use Zend\Session\ManagerInterface as Manager;
use ZendTest\Session\TestAsset\TestContainer;

/**
* @group Zend_Session
* @covers Zend\Session\AbstractContainer
*/
class AbstractContainerTest extends TestCase
{
/**
* Hack to allow running tests in separate processes
*
* @see http://matthewturland.com/2010/08/19/process-isolation-in-phpunit/
*/
protected $preserveGlobalState = false;

/**
* @var Manager
*/
protected $manager;

/**
* @var Container
*/
protected $container;

public function setUp()
{
$_SESSION = [];
Container::setDefaultManager(null);

$config = new StandardConfig([
'storage' => 'Zend\\Session\\Storage\\ArrayStorage',
]);

$this->manager = $manager = new TestAsset\TestManager($config);
$this->container = new TestContainer('Default', $manager);
}

public function tearDown()
{
$_SESSION = [];
Container::setDefaultManager(null);
}

/**
* This test case fails on zend-session 2.8.0 with the php error below and works fine on 2.7.*.
* "Only variable references should be returned by reference"
*/
public function testOffsetGetMissingKey()
{
self::assertNull($this->container->offsetGet('this key does not exist in the container'));
}
}
17 changes: 17 additions & 0 deletions test/TestAsset/TestContainer.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?php
/**
* Zend Framework (http://framework.zend.com/)
*
* @link http://github.com/zendframework/zf2 for the canonical source repository
* @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/

namespace ZendTest\Session\TestAsset;

use Zend\Session\AbstractContainer;

class TestContainer extends AbstractContainer
{
// do nothing
}

0 comments on commit 9338f1a

Please sign in to comment.