mirror of
https://github.com/smarty-php/smarty.git
synced 2025-08-05 10:54:27 +02:00
objects don't get casted to arrays anymore in {foreach}
This commit is contained in:
1
NEWS
1
NEWS
@@ -1,3 +1,4 @@
|
|||||||
|
- remove cast of object to array in foreach's from-attribute (messju)
|
||||||
- add "null" as a valid token for {if} when security is enabled (messju)
|
- add "null" as a valid token for {if} when security is enabled (messju)
|
||||||
- add javascript_charcode encoding option to mailto function
|
- add javascript_charcode encoding option to mailto function
|
||||||
(monte)
|
(monte)
|
||||||
|
@@ -1176,14 +1176,15 @@ class Smarty_Compiler extends Smarty {
|
|||||||
}
|
}
|
||||||
|
|
||||||
$output = '<?php ';
|
$output = '<?php ';
|
||||||
|
$output .= "\$_from = $from; if (!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 = (array)$from), 'iteration' => 0);\n";
|
$output .= "{$foreach_props} = array('total' => count(\$_from), 'iteration' => 0);\n";
|
||||||
$output .= "if ({$foreach_props}['total'] > 0):\n";
|
$output .= "if ({$foreach_props}['total'] > 0):\n";
|
||||||
$output .= " foreach (\$_from as $key_part\$this->_tpl_vars['$item']):\n";
|
$output .= " foreach (\$_from as $key_part\$this->_tpl_vars['$item']):\n";
|
||||||
$output .= " {$foreach_props}['iteration']++;\n";
|
$output .= " {$foreach_props}['iteration']++;\n";
|
||||||
} else {
|
} else {
|
||||||
$output .= "if (count(\$_from = (array)$from)):\n";
|
$output .= "if (count(\$_from)):\n";
|
||||||
$output .= " foreach (\$_from as $key_part\$this->_tpl_vars['$item']):\n";
|
$output .= " foreach (\$_from as $key_part\$this->_tpl_vars['$item']):\n";
|
||||||
}
|
}
|
||||||
$output .= '?>';
|
$output .= '?>';
|
||||||
|
Reference in New Issue
Block a user