Re: [PHP] eval function
Hallo Tom, am Samstag, 23. August 2003 um 05:14 hast Du Folgendes gekritzelt: TR This should do it: TR eval('${content.$databasepagename}[$i]();'); I'm afraid to say it, but it does not :-( Yesterday I was also trying to find some manual pages about eval() which would explain me the syntax. The example in the PHP-Manual is not meaning much to me. How can I print out what eval would evaluate, so I can see how to compose the string? Thx for answering again ;-) SvT -- Who is the ennemy? mailto:[EMAIL PROTECTED] -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] eval function
Hallo Tom, am Samstag, 23. August 2003 um 17:50 hast Du Folgendes gekritzelt: TR This works for me, what error message do you get? Make sure you use TR single quotes in the eval otherwise the string will get substituted TR before eval gets a look at it. TR ?php TR $contentarray = array(1='testpage'); TR function testpage(){ TR echo 'Test succceeded br'; TR } TR $i = 1; TR $databasepagename = 'array'; TR eval('${content.$databasepagename}[$i]();'); ? That's the error I find in the apache-log. On the screen, I get nothing but a white page. By the way I have error_reporting(E_ALL); but I never get errors reported... PHP Fatal error: Call to undefined function: () in /usr/local/www/showFunctions.php(77) Your script is working. But mine not... is it because I'm on a output buffer? I use ob_start() just before, because the real output is produced by the function I want to call with the eval method... Here the part of my script: $query = SELECT pagename FROM pages; $result = mysql_query($query); $a = 0; while($row = mysql_fetch_array($result, MYSQL_BOTH)){ $page[$a] = $row[pagename]; $fct[$a] = $page[$a]; $fct[$a] = substr($fct[$a],1); $fct[$a] = str_replace(.php, , $fct[$a]); $fct[$a] = ucfirst($fct[$a]); $a++; } mysql_free_result($result); ob_start(); for($b = 0; $b sizeof($fct); $b++){ if($_SERVER[PHP_SELF] == $page[$b]) eval('${content.$fct}[$b]();'); } ... The pagename in the database is stored like /about.php so I change it to About in the while-loop. The eval method is there to replace my actual code (which is static): if($_SERVER[PHP_SELF] == /login.php) contentLogin(); if($_SERVER[PHP_SELF] == /logout.php) contentLogout(); ... Using the if-cascade, it is working, for you to know that the mistake is definitly in the eval()-method... Thx for your time... SvT -- Who is the ennemy? mailto:[EMAIL PROTECTED] -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] eval function
Hallo Tom, am Samstag, 23. August 2003 um 17:50 hast Du Folgendes gekritzelt: TR Hi, TR Saturday, August 23, 2003, 10:01:54 PM, you wrote: MW Hallo Tom, MW am Samstag, 23. August 2003 um 05:14 hast Du Folgendes gekritzelt: TR This should do it: TR eval('${content.$databasepagename}[$i]();'); MW I'm afraid to say it, but it does not :-( MW Yesterday I was also trying to find some manual pages about eval() MW which would explain me the syntax. The example in the PHP-Manual is MW not meaning much to me. MW How can I print out what eval would evaluate, so I can see how to MW compose the string? MW Thx for answering again ;-) MW SvT TR This works for me, what error message do you get? Make sure you use TR single quotes in the eval otherwise the string will get substituted TR before eval gets a look at it. TR ?php TR $contentarray = array(1='testpage'); TR function testpage(){ TR echo 'Test succceeded br'; TR } TR $i = 1; TR $databasepagename = 'array'; TR eval('${content.$databasepagename}[$i]();'); ? Sorry, I got it to show errors... here: (it's almost the same than in apache-log) Notice: Undefined variable: contentArray in /usr/local/www/showFunctions.php(77) : eval()'d code on line 1 Fatal error: Call to undefined function: () in /usr/local/www/showFunctions.php(77) : eval()'d code on line 1 SvT -- Who is the ennemy? mailto:[EMAIL PROTECTED] -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] eval function
Hi, Saturday, August 23, 2003, 8:38:32 AM, you wrote: MW Hi php-general, MW I have a question about eval(); MW I'm having multiple pagenames I store in a database. I also have a lot MW of functions starting with content and then the name of the pages MW taken from the database. Ex: pagenames = about,download functions = MW contentAbout(), contentDownload(). MW Now I would like to have a loop of if to make the decision which MW function to use, like: MW for($i = 0; $i sizeof($databasepagename);$i++){ MW if($_SERVER[PHP_SELF] == $databasepagename[$i]) MW eval(content.$databasepagename[$i].();); MW } MW but that doesn't work... MW How could I achieve that? Thanks for answering... MW SvT MW -- MW Who is the ennemy? This should do it: eval('${content.$databasepagename}[$i]();'); -- regards, Tom -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] eval() function
Yes, eval() is expensive. On Sun, 14 Jan 2001, Adam Powell wrote: Hi, in my application I am making a lot of use of the eval() function, however I was wondering if this is going to cause any extra load. Does it do anything like load in the PHP engine again or anything? We just added it in and the load on our web servers went up... so I was wondering if I should be aware of anything. Thanks, Adam -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED] -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]