diff --git a/src/View/SSViewer_Scope.php b/src/View/SSViewer_Scope.php index 36af637bd..15a674477 100644 --- a/src/View/SSViewer_Scope.php +++ b/src/View/SSViewer_Scope.php @@ -186,6 +186,9 @@ class SSViewer_Scope public function getObj($name, $arguments = [], $cache = false, $cacheName = null) { $on = $this->getItem(); + if ($on === null) { + return null; + } return $on->obj($name, $arguments, $cache, $cacheName); } diff --git a/tests/php/View/SSViewerTest.php b/tests/php/View/SSViewerTest.php index b80b1c809..3b55fa9d9 100644 --- a/tests/php/View/SSViewerTest.php +++ b/tests/php/View/SSViewerTest.php @@ -364,6 +364,12 @@ SS; ); } + public function testGlobalVariablesReturnNull() + { + $this->assertEquals('

', $this->render('

$SSViewerTest_GlobalReturnsNull

')); + $this->assertEquals('

', $this->render('

$SSViewerTest_GlobalReturnsNull.Chained.Properties

')); + } + public function testCoreGlobalVariableCalls() { $this->assertEquals( diff --git a/tests/php/View/SSViewerTest/TestGlobalProvider.php b/tests/php/View/SSViewerTest/TestGlobalProvider.php index 9fccbb0c0..f005f24ce 100644 --- a/tests/php/View/SSViewerTest/TestGlobalProvider.php +++ b/tests/php/View/SSViewerTest/TestGlobalProvider.php @@ -18,8 +18,8 @@ class TestGlobalProvider implements TemplateGlobalProvider, TestOnly 'SSViewerTest_GlobalReferencedByString' => 'get_reference', 'SSViewerTest_GlobalReferencedInArray' => ['method' => 'get_reference'], - 'SSViewerTest_GlobalThatTakesArguments' => ['method' => 'get_argmix', 'casting' => 'HTMLFragment'] - + 'SSViewerTest_GlobalThatTakesArguments' => ['method' => 'get_argmix', 'casting' => 'HTMLFragment'], + 'SSViewerTest_GlobalReturnsNull' => 'getNull', ]; } @@ -43,4 +43,9 @@ class TestGlobalProvider implements TemplateGlobalProvider, TestOnly $args = func_get_args(); return 'z' . implode(':', $args) . 'z'; } + + public static function getNull() + { + return null; + } }