From 1ad91538c6eb3991cc69e3e955261550772c530c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matthias=20K=C3=BChne?= Date: Tue, 27 Jun 2017 15:11:48 +0200 Subject: [PATCH 1/3] Create testcase for retrieving a value of a non-existing key from the Abstract-Container. Worked in 2.7.x, fails on 2.8.0 --- test/AbstractContainerTest.php | 68 ++++++++++++++++++++++++++++++++ test/TestAsset/TestContainer.php | 17 ++++++++ 2 files changed, 85 insertions(+) create mode 100644 test/AbstractContainerTest.php create mode 100644 test/TestAsset/TestContainer.php diff --git a/test/AbstractContainerTest.php b/test/AbstractContainerTest.php new file mode 100644 index 00000000..2f59fd67 --- /dev/null +++ b/test/AbstractContainerTest.php @@ -0,0 +1,68 @@ + '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')); + } +} diff --git a/test/TestAsset/TestContainer.php b/test/TestAsset/TestContainer.php new file mode 100644 index 00000000..8e51b8da --- /dev/null +++ b/test/TestAsset/TestContainer.php @@ -0,0 +1,17 @@ + Date: Wed, 31 Jan 2018 11:19:29 -0600 Subject: [PATCH 2/3] Fixes issue presented in #102 and #81 This patch adds a new private member, `$defaultValue`, to the `AbstractContainer`. `offsetGet()` now returns that member in the case that the provided `$key` is not a valid offset. This resolves the issue of returning a _reference_. --- src/AbstractContainer.php | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/AbstractContainer.php b/src/AbstractContainer.php index b4e47a5c..831f4045 100644 --- a/src/AbstractContainer.php +++ b/src/AbstractContainer.php @@ -52,6 +52,11 @@ abstract class AbstractContainer extends ArrayObject */ protected static $defaultManager; + /** + * Default value to return by reference from offsetGet + */ + private $defaultValue = null; + /** * Constructor * @@ -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(); From 8ef1a576f1f6b6d2664a49666905267e56dd0675 Mon Sep 17 00:00:00 2001 From: Matthew Weier O'Phinney Date: Wed, 31 Jan 2018 11:38:41 -0600 Subject: [PATCH 3/3] Adds CHANGELOG entry for #102 --- CHANGELOG.md | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 5b874884..1d495daa 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 @@ -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