mirror of
https://github.com/twigphp/Twig.git
synced 2026-09-11 18:06:46 +00:00
fixed a PHP notice when trying to access a key on a non-object/array variable
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
* 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
|
||||
|
||||
@@ -351,9 +351,10 @@ abstract class Twig_Template implements Twig_TemplateInterface
|
||||
|
||||
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)));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -10,6 +10,20 @@
|
||||
*/
|
||||
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
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user