[prev in list] [next in list] [prev in thread] [next in thread] 

List:       smarty-dev
Subject:    Re: [SMARTY-DEV] foreach tag and objects
From:       Boris Bezrukov <lovchy () php ! net>
Date:       2005-01-17 9:10:32
Message-ID: 41EBA72B.2020203 () php ! net
[Download RAW message or body]

Boris Bezrukov wrote:

> David Zülke wrote:
>
>> Boris,
>>
>> I looked at your patch. You're removing the type casting of the 
>> variable to
>> an array. I believe this was done intentionally, because casting an 
>> int to
>> an array creates an array with one value, the int. Same goes for other
>> variable types. You cannot simply remove this.
>>
>> David
>>
>>  
>>
> David,
>
> Yes, it does create, that what I was talking about. And it's, in fact, 
> hack to allow people use scalars (scalars! not objects) in foreach 
> tag. That's not bad, but it closes posibilities of using objects 
> inside foreach tag. My patch will broke bc, yep... I apologize, do not 
> commit it. But use if (!is_object($foo)) $foo = (array)$foo; then. And 
> this will probably break one's script too. So is the price. It's 
> _really_ bad not to give people posibilities to use iterators inside 
> templates. PHP5 is OOP-driven, you can't steal such an important 
> language feature. Patch with !is_object attached.
>
I did it again :]. New patch attached here. Sorry.

>>  
>>
>>> -----Original Message-----
>>> From: Boris Bezrukov [mailto:lovchy@php.net]
>>> Sent: Monday, January 10, 2005 5:59 PM
>>> To: Boris Bezrukov
>>> Cc: smarty-dev@lists.php.net
>>> Subject: Re: [SMARTY-DEV] foreach tag and objects
>>>
>>> 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.
>>>   
>>
>>
>>  
>>
>


["oop.diff" (text/x-patch)]

Index: libs/Smarty_Compiler.class.php
===================================================================
RCS file: /repository/smarty/libs/Smarty_Compiler.class.php,v
retrieving revision 1.356
diff -r1.356 Smarty_Compiler.class.php
1162c1162,1163
<             $output .= "{$foreach_props} = array('total' => count(\$_from = \
                (array)$from), 'iteration' => 0);\n";
---
> $output .= "if (!is_oject($from)) $from = (array)$from;";
> $output .= "{$foreach_props} = array('total' => count(\$_from = $from), 'iteration' \
> => 0);\n";
1167c1168,1169
<             $output .= "if (count(\$_from = (array)$from)):\n";
---
> $output .= "if (!is_oject($from)) $from = (array)$from;";
> $output .= "if (count(\$_from = $from)):\n";



-- 
Smarty Development Mailing List (http://smarty.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic