Merge pull request #544 from carpii/Smarty2

allow StdClass to be cast to array when compiling foreach, to prevent invalid count warning in PHP 7.2+
This commit is contained in:
mohrt
2020-01-13 18:47:40 -06:00
committed by GitHub

View File

@ -1192,7 +1192,7 @@ class Smarty_Compiler extends Smarty {
}
$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)) {
$foreach_props = "\$this->_foreach[$name]";
$output .= "{$foreach_props} = array('total' => count(\$_from), 'iteration' => 0);\n";