Using dynamic methods

Why usersMethoddoesn't my dynamic method return any result? The page is always blank.

<?php
class SampleClass
{
    public function __call($name, $args)
    {
        $m = $this->methods();

        eval($m['usersMethod']);
    }

    public function methods()
    {
        $methods = array(
            'usersMethod'=>'$a=2; return $a;', 
            'membersMethod'=>'$a=1; return $a;'
        );

        return $methods;
    }
}
$sample = new SampleClass();
echo $sample->usersMethod();
?>
+3
source share
2 answers

You need to return the value eval:

return eval($m['usersMethod']);

(see this answer )

+4
source

You have an operator returnin code snippets that should be used as “functions”. But this return sends the value only through eval (). You also need to return the result of eval:

 return eval($m['usersMethod']);

Only then will the internal $ a be returned by calling the __call () method.

+2
source

All Articles