Create new class instance from string name in an aliased namespace

后端 未结 2 975
佛祖请我去吃肉
佛祖请我去吃肉 2021-01-25 16:59

I\'ve seen questions like this and this, but neither addresses how to create a class instance from a string name if you already have a namespace and the class is in an aliased n

2条回答
  •  谎友^
    谎友^ (楼主)
    2021-01-25 17:41

    You will simply have to use:

    $provider = 'League\OAuth2\Client\Provider\Google';
    

    There is no other solution, class name variables need to contain the fully qualified class name; aliasing doesn't apply to string class names, and introspection can't help you either.

提交回复
热议问题