Calling a Class function without using $this->function_name() -- PHP -- -



Calling a Class function without using $this->function_name() -- PHP -- -

so have class:

class a{ public function do_a(){ homecoming 'a_done';}; public function do_b(){ homecoming 'b_done';}; }

so require php file , create instance of class:

require_once("a_class.php"); $system = new a(); require_once("user_calls.php"); //here import user file function calls.

user_calls.php contents:

echo 'this result of '.$system->do_a(); echo 'this result of '.$system->do_b();

so, work, don't want user have utilize $system->do_a();, do_a();.

any solutions?

edit: want limit functions user phone call in user_calls.php file, basic native php functions , in class a.

disclaimer: while code works, , requested, doesn't mean advocate coding this. it's hard follow other developers (and maybe in future...), , makes utilize of eval(), bad thing(tm). said, here go:

<?php class { public function do_a() { homecoming __method__; } public function do_b() { homecoming __method__; } } $aref = new reflectionclass('a'); $apublicmethods = $aref->getmethods(reflectionmethod::is_public); foreach ($apublicmethods $method) { $php = <<<php function {$method->name}() { global \$system; homecoming \$system->{$method->name}(); } php; eval($php); } $system = new a(); echo 'this result of ' . do_a(); echo 'this result of ' . do_b();

please note if methods utilize arguments, things more hairy. also, if name of methods same function in global namespace (ex. substr()), effort redefine them, , you'll fatal error.

php class

Comments

Popular posts from this blog

How do I check if an insert was successful with MySQLdb in Python? -

delphi - blogger via idHTTP : error 400 bad request -

postgresql - ERROR: operator is not unique: unknown + unknown -