Why is the: class syntax used in Laravel source code?

Source: Internet
Author: User
From PHP5.5, the keyword class can also be used for parsing class names. You can use ClassName: class to obtain a string that contains the fully qualified name of the class ClassName. This is especially useful for classes that use namespaces. {Code...} bootstrapapp. php code...

Since PHP 5.5, the keyword class can also be used for parsing class names. You can use ClassName: class to obtain 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 been written in the bootstrap/app. php code, why should I use the: class syntax?

Reply content:

Since PHP 5.5, the keyword class can also be used for parsing class names. You can use ClassName: class to obtain 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 been written in the bootstrap/app. php code, why should I use the: class syntax?

I know someone gave the correct answer to 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, which is a string.

You should first understand the concept of Laravel containers.

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.