[PHP] Re: eval help
note that the following php: ?php /* eval testing SM 3/3/2003 1:28PM */ $name = Scott; $arr[] = Dude; $arr2[name] = Broness!; echo($arr2['name']); // test $str = brHello, $name; $str2 = brHello, $arr[0]; $str3 = brHello, $arr2['name']; eval (\$evaldString = \$str\;); echo $evaldString; eval (\$evaldString = \$str2\;); echo $evaldString; eval (\$evaldString = \$str3\;); echo $evaldString; ? produces: Broness!brHello, ScottbrHello, DudebrHello, -- note that the last cannot be seen - I'm sure I'm almost there, but I have to be able to reference an associative array. Scott -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Re: eval help
Hi, $arr2[name] = Broness!; .. $str3 = brHello, $arr2['name']; .. eval (\$evaldString = \$str3\;); echo $evaldString; Your almost there... just remember one very simple rule - if in doubt, break out. Meaning, if you're having variable resolution issues, then just break out of the string. Apply the following change to have happy dreams: From: $str3 = brHello, $arr2['name']; To: $str3 = brHello, .$arr2['name']; -- Dan Hardiker [EMAIL PROTECTED] ADAM Software Systems Engineer First Creative -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Re: eval help
Thanks Dan - I just worked this out before reading your solution! :) $str4 = brHello, .$arr2['name']; cheers and thanks to all - lets see how that goes within my framework now :) neko -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Re: eval help
Actually, I just realised that what I want to accomplish is different from my example - the main issue is with scope: ?php /* eval testing 3 SM 33/3/2003 2:32PM */ func1(); function func1() { echo(brwe're in the pipe, 5-5-5.); $str = brHello, \$name; $str2 = brHello, \$arr[0]; $str3 = brHello, \$arr2['name']; echo doEvalWithVarsInScope($str); echo doEvalWithVarsInScope($str2); echo doEvalWithVarsInScope($str3); } function doEvalWithVarsInScope($str) { echo(brtrying to eval for str=$str); $name = Scott; $arr[] = Dude; $arr2[name] = Broness!; eval (\$evaldString = \$str\;); return $evaldString; } ? -- will produce: we're in the pipe, 5-5-5. trying to eval for str= Hello, $name Hello, Scott trying to eval for str= Hello, $arr[0] Hello, Dude trying to eval for str= Hello, $arr2['name'] Hello, -- any (more) help is greatly appreciated. cheers, neko -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Re: eval help
?php /* eval testing 3 SM 33/3/2003 2:32PM */ define(NAME_TAG, name); func1(); function func1() { echo(brwe're in the pipe, 5-5-5.); $str = brHello, \$name; $str2 = brHello, \$arr[0]; $str3 = brHello, \$arr2[.NAME_TAG.]; echo doEvalWithVarsInScope($str); echo doEvalWithVarsInScope($str2); echo doEvalWithVarsInScope($str3); } function doEvalWithVarsInScope($str) { echo(brtrying to eval for str=$str and NAME_TAG:.NAME_TAG); $name = Scott; $arr[] = Dude; $arr2[NAME_TAG] = Broness!; eval (\$evaldString = \$str\;); return $evaldString; } ? -- produces: we're in the pipe, 5-5-5. trying to eval for str= Hello, $name and NAME_TAG:name Hello, Scott trying to eval for str= Hello, $arr[0] and NAME_TAG:name Hello, Dude trying to eval for str= Hello, $arr2[name] and NAME_TAG:name Hello, Broness! -- done, but it's uglier than I was hoping :( -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Re: eval help
ok - my latest in the eval saga is this: I want to be able to eval a function call anywhere in the string supplied, and the function call is not in scope when the string is defined. So -- somewhere in my code I wanted something like this: $string = brtesting nodename: \$node-getName() pagename:\$nodePageTags[.TAG_PAGENAME.]; -- where the code is evaled eventually, there is a $node object defined, so the function call should work. Of course, that currently does not work :) cheers, neko -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php