Re: [SMARTY-DEV] RE: [SMARTY] php5 Iterators.

From: Date: Tue, 25 Jan 2005 21:40:32 +0000
Subject: Re: [SMARTY-DEV] RE: [SMARTY] php5 Iterators.
References: 1  Groups: php.smarty.dev 
Request: Send a blank email to php-smarty-dev+get-2622@lists.php.net to get a copy of this message
With PHP 5 on the rise I agree that it is time for a rewrite with PHP 5 OO features in mind. Some of the things I'd like to see are the ability to instantiate Smarty with limited feature sets (cache display only, no caching, no compiling, no debugging, etc.), and making parts of the engine modular (such as the template compiler.) A lot of Smarty code is written in ways to maximize PHP 4 speed that should be cleaned up. I don't think that BC with Smarty 2.x will be a major importance, or even feasible in some cases. All thoughts/comments/help with Smarty 3.0 are welcome! Monte boots wrote:
The more I look at the iterator implementation in PHP5 (especially as it is in the 5.0.x builds) the more I think support for it should not be included into any 2.x series of Smarty. I think that a rewrite of Smarty specificially designed for PHP5 would be the "right" place to implement it. It still seems like awhile before that happens so perhaps talking about proposed feature sets, design and usage goals would be appropriate to get that ball rolling. As for 2.x support of iterators, I think it should be left out of the core and provided either as an addin or in a PHP5 only class that extends the base PHP4. Doing so can ease the transition as there are already requests for Smarty versions that obey E_STRICT and supplying an extended Smarty class intended for PHP5 is one way of supporting that and other features that would be oddball in the PHP4 implementation. xo boots --- David Zülke <dz@bitxtender.com> wrote:
We _could_ count the number of properties in the array using count((array)$foo); I can't see any way of resolving item count, position, first/last etc from an iterator. People who're using iterators are most likely aware of this and can work around it or just live with that "problem". You're right, it's time to tackle this one, but I also think the time might have come to do a complete PHP5 rewrite of Smarty. I'd be happy to help. David
-----Original Message----- From: boots [mailto:jayboots@yahoo.com] Sent: Monday, January 24, 2005 11:19 AM To: David Zülke; 'Mark Rogers'; smarty-dev@lists.php.net Cc: 'boots' Subject: RE: [SMARTY-DEV] RE: [SMARTY] php5 Iterators. --- David Z|lke <dz@bitxtender.com> wrote:
     
Couldn't we just change the array casting so it is only performed
       
if
the variable is _not_ an object? foreach($object as $key => $ value) {} is the same as foreach((array)$object as $key => $ value) {} Both will loop over the properties of an object. It will also work in PHP5. If there's an iterator defined, PHP
       
will
use it, if not, it will loop over the properties just like in the
       
good
     
old times.
       
This reminds me of some correspondance from last year -- back in
     
July
messju raised this issue with Monte and I and at the end of it the following was proposed: $_from =& $this->_tpl_vars['list']; // by ref for php4 BC if ( count($_from) && ( is_array($_from) || is_object($_from) ) ): foreach ($_from as $this->_tpl_vars['cell']): ... endforeach; else: // err endif; unset($_from); At the time, messju was against the =& so as to not raise the possiblity of subtle bugs. Otherwise, we were all in agreement that
     
it
was a reasonable approach. As I still haven't really delved into
     
PHP5,
I am in no position to understand the minute issues that might
     
arise.
My understanding is that there is a difficulty with count and the
     
need
for certain interfaces to be implemented for this to work properly
     
for
objects. For example, Bok proposed a different solution http://news.php.net/php.smarty.dev/2510 but messju pointed out some
     
of
the issues that it raised: http://news.php.net/php.smarty.dev/2515 My only concern is that too much PHP5 specific code to check for correctness gets inserted into the foreach procedure thereby
     
hampering
PHP4 performance in any way. Otherwise, it seems like the time is approaching where this needs to be addressed. xo boots -- Smarty Development Mailing List (http://smarty.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
     
-- Smarty Development Mailing List (http://smarty.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php


« previous php.smarty.dev (#2622) next »