allow StdClass to be cast to array when compiling foreach, to prevent invalid count warning in PHP 7.2+

This commit is contained in:
carpii
2019-06-14 20:44:58 +07:00
parent 957f9ce43a
commit f8717a6cf7

View File

@@ -1192,7 +1192,7 @@ class Smarty_Compiler extends Smarty {
} }
$output = '<?php '; $output = '<?php ';
$output .= "\$_from = $from; if (!is_array(\$_from) && !is_object(\$_from)) { settype(\$_from, 'array'); }"; $output .= "\$_from = $from; if ((\$_from instanceof StdClass) || (!is_array(\$_from) && !is_object(\$_from))) { settype(\$_from, 'array'); }";
if (isset($name)) { if (isset($name)) {
$foreach_props = "\$this->_foreach[$name]"; $foreach_props = "\$this->_foreach[$name]";
$output .= "{$foreach_props} = array('total' => count(\$_from), 'iteration' => 0);\n"; $output .= "{$foreach_props} = array('total' => count(\$_from), 'iteration' => 0);\n";