THINKPHP5 introduction of third-party class library methods

Source: Internet
Author: User

First, you need to extend and use a third-party class library outside of the core, and the class library is not installed through composer, so you can put it directly under the Extend directory under the app root directory, which is the officially recommended third-party extension class Library directory.


The naming conventions of the classes follow the PSR-2 and PSR-4 specifications, taking care not to create conflicts with the system's namespaces, such as the core think, the app, and the namespace defined by the composer Class library itself.

For example, if you have an extension class library with a namespace of First.second.Foo, the class is defined as follows:
namespace First\second;

Class Foo
{
}

Then the actual class file location should be: extend/first/second/foo.php

Three, three kinds of reference methods of First.second.Foo class

(1) Direct instantiation can be used:

$foo = new \first\second\foo ();

(2) referencing namespaces in the head

Use First\second\foo;
$foo = new Foo ();

(3) Class library does not use namespaces

Loader::import (' First.second.Foo ');
$foo = new \foo ();

THINKPHP5 introduction of third-party class library methods

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.