-
Notifications
You must be signed in to change notification settings - Fork 821
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
FIX Don't error if template global is null #11331
FIX Don't error if template global is null #11331
Conversation
@@ -43,4 +43,9 @@ public static function get_argmix() | |||
$args = func_get_args(); | |||
return 'z' . implode(':', $args) . 'z'; | |||
} | |||
|
|||
public static function getNull() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wanted to use : null
as a typehint here but apparently PHP doesn't allow that 😅
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
isset(null) === false && isnull(null) === true.
PHP doesn't have a concept of "is set, but is null", so I guess that makes sense 😅
public function testGlobalVariablesReturnNull() | ||
{ | ||
$this->assertEquals('<p></p>', $this->render('<p>$SSViewerTest_GlobalReturnsNull</p>')); | ||
$this->assertEquals('<p></p>', $this->render('<p>$SSViewerTest_GlobalReturnsNull.Chained.Properties</p>')); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ran this before doing the code change and can confirm it fails by throwing an exception without the code change.
Description
Fixes a bug where if template variables from a
TemplateGlobalProvider
return null and you chain off them, you'd get a null reference error.The
getObj()
method is only ever called in one place, which sets the current item in scope - so if the current item in scope is null, we just keep null as the item in scope, which results in the behaviour we expect (i.e. nulls result in just not dumping anything to the template, are falsy in if statements, etc).Manual testing steps
See reproduction steps in the issue description
Issues
null
#11330Pull request checklist