Re: foreach tag and objects

Boris Bezrukov <[email protected]>
Newsgroups gmane.comp.php.smarty.devel
Message-ID <[email protected]>
Boris Bezrukov wrote:

> Hello.
> Smarty does use (array)$from syntax within compiled {foreach} tag. I 
> suppose that was introduced to avoid errors with $from in scalar data 
> types? Is indeed comfortable for PHP4, but PHP5 had introduced 
> iterators, so objects can now be used within foreach construct either. 
> How do you think if it should be removed? Yep, it can be replaced with 
> something like if(!is_object), but should it?
>
> Patch removing them attached.
>
> Thank you.
>
Forgot to attach file.

-- 
Smarty Development Mailing List (http://smarty.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php
patch.diff (text/x-patch, 1.2 KB)
Index: Smarty_Compiler.class.php
===================================================================
RCS file: /repository/smarty/libs/Smarty_Compiler.class.php,v
retrieving revision 1.356
diff -u -r1.356 Smarty_Compiler.class.php
--- Smarty_Compiler.class.php	6 Jan 2005 17:24:36 -0000	1.356
+++ Smarty_Compiler.class.php	10 Jan 2005 13:55:37 -0000
@@ -1159,12 +1159,12 @@
         $output = '<?php ';
         if (isset($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 = $from), 'iteration' => 0);\n";
             $output .= "if ({$foreach_props}['total'] > 0):\n";
             $output .= "    foreach (\$_from as $key_part\$this->_tpl_vars['$item']):\n";
             $output .= "        {$foreach_props}['iteration']++;\n";
         } else {
-            $output .= "if (count(\$_from = (array)$from)):\n";
+            $output .= "if (count(\$_from = $from)):\n";
             $output .= "    foreach (\$_from as $key_part\$this->_tpl_vars['$item']):\n";
         }
         $output .= '?>';
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.