Skip to content

Commit 645846f

Browse files
cedric-annetrasher
authored andcommitted
Trigger warnings when accessing invalid callable/property from Twig
1 parent fa57c0c commit 645846f

File tree

1 file changed

+26
-6
lines changed

1 file changed

+26
-6
lines changed

src/Application/View/Extension/PhpExtension.php

Lines changed: 26 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -87,10 +87,11 @@ public function phpConfig(string $name)
8787
*/
8888
public function call(string $callable, array $parameters = [])
8989
{
90-
if (is_callable($callable)) {
91-
return call_user_func_array($callable, $parameters);
90+
if (!is_callable($callable)) {
91+
\trigger_error(sprintf('Invalid callable `%s`.', $callable), E_USER_WARNING);
92+
return null;
9293
}
93-
return null;
94+
return call_user_func_array($callable, $parameters);
9495
}
9596

9697
/**
@@ -103,10 +104,29 @@ public function call(string $callable, array $parameters = [])
103104
*/
104105
public function getStatic($class, string $property)
105106
{
106-
if ((is_object($class) || class_exists($class)) && property_exists($class, $property)) {
107-
return $class::$$property;
107+
if (!is_object($class) && !class_exists($class)) {
108+
\trigger_error(
109+
sprintf(
110+
'Invalid class or object `%s`.',
111+
\is_string($class) ? $class : \get_debug_type($class)
112+
),
113+
E_USER_WARNING
114+
);
115+
return null;
108116
}
109-
return null;
117+
if (!property_exists($class, $property)) {
118+
\trigger_error(
119+
sprintf(
120+
'Invalid property `%s::%s.',
121+
\is_string($class) ? $class : \get_debug_type($class),
122+
$property
123+
),
124+
E_USER_WARNING
125+
);
126+
return null;
127+
}
128+
129+
return $class::$$property;
110130
}
111131

112132
/**

0 commit comments

Comments
 (0)