mirror of
https://github.com/twigphp/Twig.git
synced 2026-09-16 20:36:33 +00:00
merged branch drewjw81/extension_global_fix (PR #1053)
This PR was squashed before being merged into the master branch (closes #1053).
Discussion
----------
Prevent extensions from clobbering all globals.
It's possible for a poorly written extension to destroy all global variables by returning nothing. This prevents that and throws an E_WARNING to notify the developer.
Commits
-------
7c8acf7 Prevent extensions from clobbering all globals.
This commit is contained in:
@@ -1099,7 +1099,12 @@ class Twig_Environment
|
||||
{
|
||||
$globals = array();
|
||||
foreach ($this->extensions as $extension) {
|
||||
$globals = array_merge($globals, $extension->getGlobals());
|
||||
$extGlob = $extension->getGlobals();
|
||||
if (!is_array($extGlob)) {
|
||||
throw new UnexpectedValueException(sprintf('"%s::getGlobals()" must return an array of globals.', get_class($extension)));
|
||||
}
|
||||
|
||||
$globals = array_merge($globals, $extGlob);
|
||||
}
|
||||
|
||||
return array_merge($globals, $this->staging->getGlobals());
|
||||
|
||||
Reference in New Issue
Block a user