Skip to content

Commit

Permalink
bug #3097 Fix using array_key_exists() on objects, it is deprecated i…
Browse files Browse the repository at this point in the history
…n PHP 7.4 (nicolas-grekas)

This PR was merged into the 1.x branch.

Discussion
----------

Fix using array_key_exists() on objects, it is deprecated in PHP 7.4

Found as part of symfony/symfony#32844

Commits
-------

d0550b7 Fix using array_key_exists() on objects, it is deprecated in PHP 7.4
  • Loading branch information
fabpot committed Aug 2, 2019
2 parents ef4ae44 + d0550b7 commit 1845893
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/Template.php
Expand Up @@ -537,7 +537,7 @@ protected function getAttribute($object, $item, array $arguments = [], $type = s
if (self::METHOD_CALL !== $type) {
$arrayItem = \is_bool($item) || \is_float($item) ? (int) $item : $item;

if (((\is_array($object) || $object instanceof \ArrayObject) && (isset($object[$arrayItem]) || \array_key_exists($arrayItem, $object)))
if (((\is_array($object) || $object instanceof \ArrayObject) && (isset($object[$arrayItem]) || \array_key_exists($arrayItem, (array) $object)))
|| ($object instanceof \ArrayAccess && isset($object[$arrayItem]))
) {
if ($isDefinedTest) {
Expand Down Expand Up @@ -604,7 +604,7 @@ protected function getAttribute($object, $item, array $arguments = [], $type = s

// object property
if (self::METHOD_CALL !== $type && !$object instanceof self) { // \Twig\Template does not have public properties, and we don't want to allow access to internal ones
if (isset($object->$item) || \array_key_exists((string) $item, $object)) {
if (isset($object->$item) || \array_key_exists((string) $item, (array) $object)) {
if ($isDefinedTest) {
return true;
}
Expand Down

0 comments on commit 1845893

Please sign in to comment.