Skip to content
Snippets Groups Projects
call.php 1.47 KiB
Newer Older
Sibidharan's avatar
Sibidharan committed
<pre><?php
Sibidharan's avatar
Sibidharan committed

class Superhero {
    public function __construct($name){
        $this->name = $name;
    }

    public function __call($method, $args){
        echo "Method Called: $method\n";
        var_dump($args);

        $methods = get_class_methods('Superhero');
        var_dump($methods);

        foreach($methods as $m){
            if($m == $method){
                echo("Calling the private function from __call(): ".$m."\n");
                return $this->$m();
            }
        }
        $dir = __DIR__.'/api/apis';
        $methods = scandir($dir);
Sibidharan's avatar
Sibidharan committed
        var_dump($methods);
Sibidharan's avatar
Sibidharan committed
        foreach($methods as $m){
            if($m == "." or $m == ".."){
                continue;
            }
            $basem = basename($m, '.php');
            echo "Trying to call $basem() for $method()\n";
            if($basem == $method){
                include $dir."/".$m;
                $func = Closure::bind(${$basem}, $this, get_class());
                if(is_callable($func)){
                    return call_user_func_array($func, $args);
                } else {
                    echo "Something is wrong";
                }
            }
        }

    }

    private function getName(){
        return $this->name;
    }
}

$hero = new Superhero("Batman");
Sibidharan's avatar
Sibidharan committed
echo date_default_timezone_get();
echo date("Y-m-d h:i:s a", time());
Sibidharan's avatar
Sibidharan committed
echo $hero->getName()."\n";
echo $hero->get_powers();
Sibidharan's avatar
Sibidharan committed
//session_start();
$_SESSION['hello'] = 'world';
print_r($_SESSION);
Sibidharan's avatar
Sibidharan committed

Sibidharan's avatar
Sibidharan committed
//var_dump($_SERVER);
Sibidharan's avatar
Sibidharan committed

Sibidharan's avatar
Sibidharan committed

?>
</pre>