Re[2]: [PHP] eval function
| From: | Tom Rogers | Date: | Sat, 23 Aug 2003 17:32:56 +0000 |
| Subject: | Re[2]: [PHP] eval function | ||
| References: | 1 2 3 4 5 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-160513@lists.php.net to get a copy of this message | ||
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:elektrik@gmx.net
Ok we have to do it in 2 steps like this:
eval('$fn="content".$fct[$b];$fn();');
--
regards,
Tom