PHPTALとSmarty
PHPTALとSmartyの処理の違い。
PHPTALのPHP5専用のものを使っています。
その場合、キャッシュで展開されるソースは
<?php $__repeat__ = $ctx->repeat ; if (!isset($ctx->fruit)): ; $ctx->fruit = false ; endif ; $__repeat__->fruit = new PHPTAL_RepeatController($ctx->fruits) ; foreach ($__repeat__->fruit->source as $__key__ => $ctx->fruit ): ; $__repeat__->fruit->key = $__key__ ; $__repeat__->fruit->index = $__repeat__->fruit->index +1 ; $__repeat__->fruit->number = $__repeat__->fruit->number +1 ; $__repeat__->fruit->even = $__repeat__->fruit->index % 2 == 0 ; $__repeat__->fruit->odd = !$__repeat__->fruit->even ; if ($__repeat__->fruit->number == $__repeat__->fruit->length): ; $__repeat__->fruit->end = true ; endif ; ?><li><?php echo phptal_escape(phptal_path($ctx->fruit, 'pref', true), ENT_QUOTES, 'UTF-8');?></li><?php $__repeat__->fruit->start = false ; endforeach ; ?>
と展開される。イタレータを使っているようで。
Smartyの場合は
<?php $_from = $this->_tpl_vars['fruits']; if (!is_array($_from) && !is_object($_from)) { settype($_from, 'array'); }if (count($_from)): foreach ($_from as $this->_tpl_vars['result']): ?> <li><?php echo $this->_tpl_vars['result']; ?></li> <?php endforeach; endif; unset($_from); ?>
ということで普通のFOREACHということになります。