Laravel source code inside why to use:: Class syntax?

Source: Internet
Author: User

Since PHP 5.5, keyword class can also be used to parse the class name. With Classname::class you can get a string that contains the fully qualified name of the class ClassName. This is especially useful for classes that use namespaces.

$app->singleton(    Illuminate\Contracts\Http\Kernel::class,    App\Http\Kernel::class);$app->singleton(    Illuminate\Contracts\Console\Kernel::class,    App\Console\Kernel::class);$app->singleton(    Illuminate\Contracts\Debug\ExceptionHandler::class,    App\Exceptions\Handler::class);

Since the fully qualified name of the class has already been written in this bootstrap/app.php code, why use:: Class syntax?

Reply content:

Since PHP 5.5, keyword class can also be used to parse the class name. With Classname::class you can get a string that contains the fully qualified name of the class ClassName. This is especially useful for classes that use namespaces.

$app->singleton(    Illuminate\Contracts\Http\Kernel::class,    App\Http\Kernel::class);$app->singleton(    Illuminate\Contracts\Console\Kernel::class,    App\Console\Kernel::class);$app->singleton(    Illuminate\Contracts\Debug\ExceptionHandler::class,    App\Exceptions\Handler::class);

Since the fully qualified name of the class has already been written in this bootstrap/app.php code, why use:: Class syntax?

People who know the right answer https://www.zhihu.com/questio ...

This is the type App\http\kernel, which is the object type of a class;

This is the class name string Apphttpkernel::class of the class, which is the string.

This question you first understand Laravel's container concept.

  • 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.