merged branch mvrhov/patch-1 (PR #603)

Commits
-------

95f8af7 cast $name to a string as $name can in fact be an object implementing __toString function as true in my case.

Discussion
----------

cast $name to a string ...

... because $name can be an object implementing __toString. I have Enum type implementation which implements __toString. Without the cast I'm getting the following exception:
"An exception has been thrown during the rendering of a template ("Warning: Illegal offset type in isset or empty in... "

---------------------------------------------------------------------------

by fabpot at 2012-01-18T08:43:23Z

From where do you call these methods? from your code? from a template?

---------------------------------------------------------------------------

by mvrhov at 2012-01-18T11:17:55Z

I put the enum object as variable into the template and then based on the enum value I display a block.
This commit is contained in:
Fabien Potencier
2012-02-18 10:00:52 +01:00
+5 -1
View File
@@ -98,6 +98,8 @@ abstract class Twig_Template implements Twig_TemplateInterface
*/
public function displayParentBlock($name, array $context, array $blocks = array())
{
$name = (string) $name;
if (isset($this->traits[$name])) {
$this->traits[$name][0]->displayBlock($name, $context, $blocks);
} elseif (false !== $parent = $this->getParent($context)) {
@@ -119,6 +121,8 @@ abstract class Twig_Template implements Twig_TemplateInterface
*/
public function displayBlock($name, array $context, array $blocks = array())
{
$name = (string) $name;
if (isset($blocks[$name])) {
$b = $blocks;
unset($b[$name]);
@@ -189,7 +193,7 @@ abstract class Twig_Template implements Twig_TemplateInterface
*/
public function hasBlock($name)
{
return isset($this->blocks[$name]);
return isset($this->blocks[(string) $name]);
}
/**