Re[2]: [PHP] eval function

2003-08-23 Thread Tom Rogers
Hi,

Sunday, August 24, 2003, 2:32:01 AM, you wrote:

MW> That's the error I find in the apache-log. On the screen, I get
MW> nothing but a white page. By the way I have error_reporting(E_ALL);
MW> but I never get errors reported...

MW> PHP Fatal error:  Call to undefined function:  () in 
/usr/local/www/showFunctions.php(77)

MW> Your script is working. But mine not... is it because I'm on a output
MW> buffer? I use ob_start() just before, because the real output is
MW> produced by the function I want to call with the eval method...

MW> Here the part of my script:

MW> $query = "SELECT pagename FROM pages";
MW> $result = mysql_query($query);
MW> $a = 0;
MW> while($row = mysql_fetch_array($result, MYSQL_BOTH)){
MW>   $page[$a] = $row["pagename"];
MW>   $fct[$a] = $page[$a];
MW>   $fct[$a] = substr($fct[$a],1);
MW>   $fct[$a] = str_replace(".php", "", $fct[$a]);
MW>   $fct[$a] = ucfirst($fct[$a]);
MW>   $a++;
MW> }
MW> mysql_free_result($result);

MW> ob_start();

MW> for($b = 0; $b < sizeof($fct); $b++){
MW>   if($_SERVER["PHP_SELF"] == $page[$b])
MW> eval('${"content".$fct}[$b]();');
MW> }

MW> ...

MW> The "pagename" in the database is stored like /about.php so I change
MW> it to About in the while-loop.

MW> The eval method is there to replace my actual code (which is static):
MW> if($_SERVER["PHP_SELF"] == "/login.php")
MW>   contentLogin();
MW> if($_SERVER["PHP_SELF"] == "/logout.php")
MW>   contentLogout();

MW> ...

MW> Using the "if-cascade", it is working, for you to know that the
MW> mistake is definitly in the eval()-method...

MW> Thx for your time...

MW> SvT


MW> -- 
MW> Who is the ennemy?

MW> mailto:[EMAIL PROTECTED]



Ok we have to do it in 2 steps like this:

eval('$fn="content".$fct[$b];$fn();');

-- 
regards,
Tom


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re[2]: [PHP] eval function

2003-08-23 Thread Tom Rogers
Hi,

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

This works for me, what error message do you get? Make sure you use
single quotes in the eval otherwise the string will get substituted
before eval gets a look at it.

'testpage');
function testpage(){
echo 'Test succceeded ';
}
$i = 1;
$databasepagename = 'array';

eval('${"content".$databasepagename}[$i]();');
?>

-- 
regards,
Tom


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php