Hello, all SO users!
I have a bit of PHP code (for the module feature of my CMS (not drupal) which allows people to view pages, comments, forum posts, blog posts, etc...):
if(isset($_GET["m"]))
{
    //Does the module exist and activated, and has it a function called view?
    if(isset($module_exists[$_GET["m"]]) && method_exists($_GET["m"], "view"))//Yep
    {
     //Load view (should be an array)
     eval("$module_view = ".$_GET["m"]."::view();");
     if(!is_array($module_view))//Not an array :(
     {
      error::e500module($_GET["m"], $_SERVER["REQUEST_URI"]);
     }
    }
    else//Nope, so display error
    {
     error::e404($_SERVER['REQUEST_URI']);
    }
}
Now, I get this errors when parsing the page:
Notice: Undefined variable: module_view in C:\wamp\www\SYSTEM\start.php on line 34
Parse error: parse error in C:\wamp\www\SYSTEM\start.php(34) : eval()'d code on line 1
Notice: Undefined variable: module_view in C:\wamp\www\SYSTEM\start.php on line 35
But when I do:
eval("print_r(".$_GET["m"]."::view());");
instead of:
eval("$module_view = ".$_GET["m"]."::view();");
I don't get any error, but simply the array printed. Does anyone know what I do wrong? I don't understand it. Please don't tell me that eval() is not safe, I know.
Thanks.