* 1.7.0 (2012-XX-XX)
+ * fixed a PHP notice when trying to access a key on a non-object/array variable
* enhanced error reporting when the template file is an instance of SplFileInfo
* added Twig_Environment::mergeGlobals()
* added compilation checks to avoid misuses of the sandbox tag
if (is_object($object)) {
throw new Twig_Error_Runtime(sprintf('Key "%s" in object (with ArrayAccess) of type "%s" does not exist', $item, get_class($object)));
- // array
- } else {
+ } elseif (is_array($object)) {
throw new Twig_Error_Runtime(sprintf('Key "%s" for array with keys "%s" does not exist', $item, implode(', ', array_keys($object))));
+ } else {
+ throw new Twig_Error_Runtime(sprintf('Impossible to access a key ("%s") on a "%s" variable', $item, gettype($object)));
}
}
}
class Twig_Tests_TemplateTest extends PHPUnit_Framework_TestCase
{
/**
+ * @expectedException Twig_Error_Runtime
+ * @expectedExceptionMessage Impossible to access a key ("a") on a "string" variable
+ */
+ public function testAttributeOnAString()
+ {
+ $template = new Twig_TemplateTest(
+ new Twig_Environment(null, array('strict_variables' => true)),
+ false
+ );
+
+ $template->getAttribute('string', 'a', array(), Twig_TemplateInterface::ARRAY_CALL, false);
+ }
+
+ /**
* @dataProvider getGetAttributeTests
*/
public function testGetAttribute($defined, $value, $object, $item, $arguments, $type, $useExt = false)