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:
Fabien Potencier
2013-04-12 11:46:40 +02:00
+6 -1
View File
@@ -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());