diff --git a/src/Symfony/Component/HttpFoundation/Session/Attribute/NamespacedAttributeBag.php b/src/Symfony/Component/HttpFoundation/Session/Attribute/NamespacedAttributeBag.php index 138aa36145..25dcd22869 100644 --- a/src/Symfony/Component/HttpFoundation/Session/Attribute/NamespacedAttributeBag.php +++ b/src/Symfony/Component/HttpFoundation/Session/Attribute/NamespacedAttributeBag.php @@ -46,6 +46,10 @@ class NamespacedAttributeBag extends AttributeBag $attributes = $this->resolveAttributePath($name); $name = $this->resolveKey($name); + if (null === $attributes) { + return false; + } + return array_key_exists($name, $attributes); } @@ -57,6 +61,10 @@ class NamespacedAttributeBag extends AttributeBag $attributes = $this->resolveAttributePath($name); $name = $this->resolveKey($name); + if (null === $attributes) { + return $default; + } + return array_key_exists($name, $attributes) ? $attributes[$name] : $default; } @@ -120,12 +128,8 @@ class NamespacedAttributeBag extends AttributeBag unset($parts[count($parts)-1]); foreach ($parts as $part) { - if (!array_key_exists($part, $array)) { - if (!$writeContext) { - return $array; - } - - $array[$part] = array(); + if (null !== $array && !array_key_exists($part, $array)) { + $array[$part] = $writeContext ? array() : null; } $array = & $array[$part]; diff --git a/src/Symfony/Component/HttpFoundation/Tests/Session/Attribute/NamespacedAttributeBagTest.php b/src/Symfony/Component/HttpFoundation/Tests/Session/Attribute/NamespacedAttributeBagTest.php index 432499e945..0f9ef0fb33 100644 --- a/src/Symfony/Component/HttpFoundation/Tests/Session/Attribute/NamespacedAttributeBagTest.php +++ b/src/Symfony/Component/HttpFoundation/Tests/Session/Attribute/NamespacedAttributeBagTest.php @@ -160,8 +160,10 @@ class NamespacedAttributeBagTest extends \PHPUnit_Framework_TestCase array('csrf.token/b', '4321', true), array('category', array('fishing' => array('first' => 'cod', 'second' => 'sole')), true), array('category/fishing', array('first' => 'cod', 'second' => 'sole'), true), + array('category/fishing/missing/first', null, false), array('category/fishing/first', 'cod', true), array('category/fishing/second', 'sole', true), + array('category/fishing/missing/second', null, false), array('user2.login', null, false), array('never', null, false), array('bye', null, false),