Re: [SMARTY] <help!>EVAL()</help!>

From: Date: Thu, 22 Aug 2002 08:37:10 +0000
Subject: Re: [SMARTY] <help!>EVAL()</help!>
Groups: php.smarty.general 
Request: Send a blank email to php-smarty-general+get-5804@lists.php.net to get a copy of this message
On 19 Aug 2002 at 18:32, Shaowarrior wrote: > eval('$img'."\$ext".'[$c_'."\$ext".'] = > $repertoire.basename($nomFichier); > $c_'."\$ext".'++; > return();'); In order to debug this it is helpful to output the string you eval() - eg. print '$img' . "\$ext" . '[$c_' . "\$ext" . '] = $repertoire . basename($nomFichier); $c_' . "\$ext"' . '++; return ();'; This would output $img$ext[$c_$ext] = $repertoire . basename($nomFichier); $c_$ext++; return (); You see, $img$ext and $c_$ext are nonsense, this is why you get the error > PARSE ERROR: parse error, unexcepted T_VARIABLE in c:\[...](20): > eval()'d code on line 1 as the parser does not expect the $ext variable after $img. The string "\$ext" is the same as '$ext' as the \ escapes the $ sign. If you want to use the _value_ of $ext in your eval, use it without quotes or without escaping $: $code = '$img' . $ext . '[$c_' . $ext . '] = $repertoire .' . ' basename($nomFichier); $c_' . $ext . '++; ' . 'return ();'; eval($code); > > This is it! Yeah, that's it. :-) By the way: I would not use the eval here. Your switch() is cleaner and faster and does also work if $ext is neither GIF nor JPG. HTH, -- Ferdinand Beyer <fbeyer@clickhand.de>

« previous php.smarty.general (#5804) next »