Re: [SMARTY-DEV] Loop problems with new object support

From: Date: Mon, 20 Jan 2003 23:01:51 +0000
Subject: Re: [SMARTY-DEV] Loop problems with new object support
References: 1  Groups: php.smarty.dev 
Request: Send a blank email to php-smarty-dev+get-565@lists.php.net to get a copy of this message
You came upon an issue here. (sidenote, there was a syntax problem with foreach, I have a fix for that.) The problem is with foreach. Foreach creates a temporary variable at runtime which does not exist during compile time, so it gets treated as an array. This problem will also crop up with any variables assigned at runtime. Either we need to use a different syntax for objects, or we make a runtime function that determines what the "." means. I'll try a runtime function and see if this affects performance by any noticable margin. As for 4.3.0 dereferening, I don't see a problem, each "." should compile correctly depending on what is assigned. Monte David Heinemeier Hansson wrote:
Excellent to see some official support for objects in Smarty brewing! This has been my by far biggest gripe for my entire Smarty time. It does seem like the new support has some problems with loops, though. {$thread.methodReturningObjectArray whichArray="responses" assign="responses"} {foreach from=$responses item=response}
    <li>{$response.title}</li>
{/foreach} {$response.title} doesn't access the right attribute, but {$response->title} does. Also, it's slightly annoying that you have to do the foreach setup in two steps. I'd like {foreach from=$thread.methodReturningObjectArray("responses") item=response} much better. Is that just me? How will this extension handle PHP 4.3.0's way of dereferencing? It would be very nice to be able to {$object.methodReturningOtherObject.otherObject.otherObjectAttribute}. -- David Heinemeier Hansson http://www.loudthinking.com/ -- Broadcasting Brain


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