Repository navigation
Allow for-loop for stdClass-objects. - #5000
antoineveldhoven wants to merge 1 commit into
Conversation
|
Thanks for the report and the PR. This current behavior is intended: the Supporting |
|
@fabpot can you elaborate why this would cause a security issue? In plain PHP you can also iterate over properties in stdClass, since they are all "public". For all I know these changes only affect the ForLoop in TwigPHP. If I want to access the stdClass I still can do: <?php
require_once '/path/to/vendor/autoload.php';
$loader = new \Twig\Loader\FilesystemLoader('/path/to/templates');
$twig = new \Twig\Environment($loader, [
'cache' => '/path/to/compilation_cache',
]);
$std_Class = (object) ['obj' => (object) ['key1' => 'one', 'key2' => 'two']];
$template = '
{% set json = std_Class.obj|json_encode|raw|split(",") %}
{% for item in json %}
{% set pair = item|replace({"\"": ""})|replace({"{": ""})|replace({"}": ""})|split(":") %}
{{ pair.0 }}: {{ pair.1 }}
{% endfor %}
';
$loader->setTemplate('template', $template);
$output = $twig->render('template', ['std_Class' => $std_Class])); |
Aiming to provide a fix for #4999