Package home | Report new bug | New search | Development Roadmap Status: Open | Feedback | All | Closed Since Version 1.3.13

Request #6212 can't use foreach with a method call
Submitted: 2005-12-09 17:20 UTC
From: koeglstefan at gmx dot at Assigned: alan_k
Status: Closed Package: HTML_Template_Flexy
PHP Version: 5.0.5 OS: Gentoo Linux
Roadmaps: (Not assigned)    
Subscription  


 [2005-12-09 17:20 UTC] koeglstefan at gmx dot at
Description: ------------ Using a foreach-loop with a method call which returns a array in the form {foreach:object.method(),var} returns the following error Parse error: parse error, unexpected '}' in /tmp/flexy_compiled_templates/<path>/info.html.en.php on line 18 Test script: --------------- {foreach:object.method(),var} {do_something()} {end:}

Comments

 [2005-12-12 04:35 UTC] alan_k
it's not supported, I dont think any of the documentation hints that it might be. - It's trivial to work around - If you want to create a patch to fix, feel free to send me it. Leaving as an open Feature Request
 [2005-12-14 22:18 UTC] mkliewe at gmx dot de
Would be nice if it will be added. I know the documentation only says that there should be a variable, but in the construct <tr flexy:foreach="object.getMethod(),m"> <td></td> </tr> the documentation also says there should be a variable, but in that case the method-call is working. So it cannot be too hard to get a method-call in a "normal" foreach-loop working.
 [2006-06-22 09:33 UTC] jan at motubo dot com (jan)
i agree with stefan, its annoying to can't use method calls within {foreach...}. tried to patch this - the tokenizer does the parsing, right? its nearly impossible to patch this "cryptic" code for anyone who has not wrote this class. but: as stefan wrote, <tr flexy:foreach="object.getMethod(),m"> works with methods. Is this a bug which will be fixed soon or will this stay a feature so we can use this...???
 [2008-04-06 21:48 UTC] silvan (Silvan Thus)
flexy:foreach="object.getMethod(),m" : works flexy:foreach="object.getMethod(singleParameter),m" : also works flexy:foreach="object.getMethod(parameterOne,parameterTwo),m" : does NOT work the tokenizer chokes on the ','
 [2010-03-17 15:36 UTC] yyougoboss (Netlogix dev)
I have the same problem with flexy:foreach="object.getMethod(parameterOne,parameterTwo),m" A solution ?
 [2010-03-18 05:11 UTC] alan_k (Alan Knowles)
the flexy:foreach syntax should be alot easier to fix: Flexy/Compiler/Tag.php parseAttributeForeach() Just does this. $foreachObj = $this->element->factory('Foreach', explode(',',$foreach), $this->element->line); to handle something more complex, you would probably want to mess around with the $foreach var, and see if '(' comes before ',', then look for ')' first... for the tokenizer, you would need to duplicate these methods <YYINITIAL,IN_CDATA>"{foreach:"{FLEXY_VAR}"}" and use METHOD as the first option. <YYINITIAL,IN_CDATA>"{foreach:"{FLEXY_METHOD}"}"
 [2010-04-27 13:28 UTC] foxdie (ano nymous)
hi, i use the following regular expression in Tag::parseAttributeForeach() $regs = array(); if( ereg( "([^(]+\([^)]+\,[^)]+\))\,(.*)", $foreach, $regs ) ) $foreachTokens = array_merge( array( $regs[ 1 ] ), explode( ",", $regs[ 2 ] ) ); //function with multiple parameters else $foreachTokens = explode( ",", $foreach ); //usual $foreachObj = $this->element->factory('Foreach', $foreachTokens, $this->element->line); don't know how to create the patch :o/
 [2010-04-28 08:36 UTC] alan_k (Alan Knowles)
 [2010-04-28 13:51 UTC] foxdie (ano nymous)
it works great! thanks ^^
 [2010-04-28 14:25 UTC] alan_k (Alan Knowles)
-Status: Feedback +Status: Closed -Assigned To: +Assigned To: alan_k
This bug has been fixed in SVN. If this was a documentation problem, the fix will appear on pear.php.net by the end of next Sunday (CET). If this was a problem with the pear.php.net website, the change should be live shortly. Otherwise, the fix will appear in the package's next release. Thank you for the report and for helping us make PEAR better.