<?php
# model.php
namespace Model\TestModel;
class User
{
public function get()
{
return '爱因斯坦';
}
}
<?php
# run.php
use Model\TestModel\User;
require __DIR__ . '/model.php';
$user = new User();
echo $user->get();
I want to implement the same usage as Laravel Facades, load.php
How to write it?
<?php
# run.php
require __DIR__ . '/load.php';
echo \User::get();
You need to implement a Facade object yourself to proxy all method calls to the real object.
Any static method call to UserFacade will be proxied to User.
__callStatic
is triggered when there is a static call. The passed parameter $name is the method name ofUserFacade::get
static call, and $arguments is the array of parameters.Laravel official description Facade is a concise and easy-to-remember class call. Laravel basically provides the Facade class for its features. At the level of business development, I do not recommend the design method of static class calling. I will open a separate post to discuss this.
Reference
https://laravel.com/docs/5.4/…
http://php.net/manual/en/lang...
http://php.net/manual/en/func...