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

Commit 9338f1a

Browse files
committed
Merge branch 'hotfix/102'
Close #102 Fixes #81
2 parents dc2c46a + 8ef1a57 commit 9338f1a

File tree

4 files changed

+98
-2
lines changed

4 files changed

+98
-2
lines changed

CHANGELOG.md

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

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

5-
## 2.8.4 - TBD
5+
## 2.8.4 - 2018-01-31
66

77
### Added
88

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

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

3945
### Added

src/AbstractContainer.php

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,11 @@ abstract class AbstractContainer extends ArrayObject
5252
*/
5353
protected static $defaultManager;
5454

55+
/**
56+
* Default value to return by reference from offsetGet
57+
*/
58+
private $defaultValue = null;
59+
5560
/**
5661
* Constructor
5762
*
@@ -425,7 +430,7 @@ public function offsetExists($key)
425430
public function &offsetGet($key)
426431
{
427432
if (! $this->offsetExists($key)) {
428-
return;
433+
return $this->defaultValue;
429434
}
430435
$storage = $this->getStorage();
431436
$name = $this->getName();

test/AbstractContainerTest.php

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
<?php
2+
/**
3+
* Zend Framework (http://framework.zend.com/)
4+
*
5+
* @link http://github.com/zendframework/zf2 for the canonical source repository
6+
* @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
7+
* @license http://framework.zend.com/license/new-bsd New BSD License
8+
*/
9+
10+
namespace ZendTest\Session;
11+
12+
use PHPUnit\Framework\TestCase;
13+
use Zend\Session\Container;
14+
use Zend\Session\Config\StandardConfig;
15+
use Zend\Session\ManagerInterface as Manager;
16+
use ZendTest\Session\TestAsset\TestContainer;
17+
18+
/**
19+
* @group Zend_Session
20+
* @covers Zend\Session\AbstractContainer
21+
*/
22+
class AbstractContainerTest extends TestCase
23+
{
24+
/**
25+
* Hack to allow running tests in separate processes
26+
*
27+
* @see http://matthewturland.com/2010/08/19/process-isolation-in-phpunit/
28+
*/
29+
protected $preserveGlobalState = false;
30+
31+
/**
32+
* @var Manager
33+
*/
34+
protected $manager;
35+
36+
/**
37+
* @var Container
38+
*/
39+
protected $container;
40+
41+
public function setUp()
42+
{
43+
$_SESSION = [];
44+
Container::setDefaultManager(null);
45+
46+
$config = new StandardConfig([
47+
'storage' => 'Zend\\Session\\Storage\\ArrayStorage',
48+
]);
49+
50+
$this->manager = $manager = new TestAsset\TestManager($config);
51+
$this->container = new TestContainer('Default', $manager);
52+
}
53+
54+
public function tearDown()
55+
{
56+
$_SESSION = [];
57+
Container::setDefaultManager(null);
58+
}
59+
60+
/**
61+
* This test case fails on zend-session 2.8.0 with the php error below and works fine on 2.7.*.
62+
* "Only variable references should be returned by reference"
63+
*/
64+
public function testOffsetGetMissingKey()
65+
{
66+
self::assertNull($this->container->offsetGet('this key does not exist in the container'));
67+
}
68+
}

test/TestAsset/TestContainer.php

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
<?php
2+
/**
3+
* Zend Framework (http://framework.zend.com/)
4+
*
5+
* @link http://github.com/zendframework/zf2 for the canonical source repository
6+
* @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
7+
* @license http://framework.zend.com/license/new-bsd New BSD License
8+
*/
9+
10+
namespace ZendTest\Session\TestAsset;
11+
12+
use Zend\Session\AbstractContainer;
13+
14+
class TestContainer extends AbstractContainer
15+
{
16+
// do nothing
17+
}

0 commit comments

Comments
 (0)