diff --git a/src/View/SSViewer_Scope.php b/src/View/SSViewer_Scope.php index f82b84062d8..3733dd3af5e 100644 --- a/src/View/SSViewer_Scope.php +++ b/src/View/SSViewer_Scope.php @@ -177,6 +177,9 @@ public function resetLocalScope() public function getObj($name, $arguments = [], $cache = false, $cacheName = null) { $on = $this->itemIterator ? $this->itemIterator->current() : $this->item; + 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 ce91527f3d7..2ce97e2b97e 100644 --- a/tests/php/View/SSViewerTest.php +++ b/tests/php/View/SSViewerTest.php @@ -364,6 +364,12 @@ public function testGlobalVariablesAreEscaped() ); } + 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 9fccbb0c064..f005f24ce1b 100644 --- a/tests/php/View/SSViewerTest/TestGlobalProvider.php +++ b/tests/php/View/SSViewerTest/TestGlobalProvider.php @@ -18,8 +18,8 @@ public static function get_template_global_variables() '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 @@ public static function get_argmix() $args = func_get_args(); return 'z' . implode(':', $args) . 'z'; } + + public static function getNull() + { + return null; + } }