<?php namespace app\index\controller; use app\index\facade\Test; class Demo2 { public function index($name='ThinkPHP') { //$test=new \app\index\common\Test(); //return $test->hello($name); /** *若是想靜態調用一個動態方法,須要給當前的類綁定一個靜態代理的類 *若是沒有在靜態代理類中顯示指定要綁定的類名,就須要動態顯示綁定一下 *\think\Facade::bind() */ \think\Facade::bind('app\index\facade\Test','app\index\common\Test'); return Test::hello('peer'); } }
<?php namespace app\index\common; class Test { public function hello($name){ return 'hello '.$name; } }
<?php namespace app\index\facade; class Test extends \think\Facade { /* protected static function getFacadeClass() { return 'app\index\common\Test'; } */ }