Home  >  Q&A  >  body text

Please advise on PHP class library loading rules

I have a question. . My project loads classes purely through a custom namespace. Then I will introduce a third-party class library. This class library is loaded according to the PSR-4 specification. In this case. How can I reference this third-party class library in the project without changing my original loading rules?

过去多啦不再A梦过去多啦不再A梦2701 days ago551

reply all(3)I'll reply

  • 阿神

    阿神2017-05-27 17:45:28

    Composer introduces a third-party class library, and introduces composer's autoload.php in the entry file to automatically load the file

    reply
    0
  • 某草草

    某草草2017-05-27 17:45:28

    The project has an entry file, just require it in the entry file

    reply
    0
  • PHP中文网

    PHP中文网2017-05-27 17:45:28

    First require the third-party class library, and then use it. Then you can instantiate this class, for example:

    <?php
    namespace common\services\money;
    
    require_once ROOT_PATH . '/extensions/payssion/lib/PayssionClient.php';
    
    use PayssionClient;
    
    class PayssionService
    {
        public function test()
        {
            $payssion = new PayssionClient();
        }
    }
    

    reply
    0
  • Cancelreply