2

Sorry for weak English!
I know ClassName::Class will return class name with namespace.
but why in laravel used this when class name is written with namespace?
like:

\App\Http\Middleware\TrimStrings::class

I'm confused about it!
Can someone tell me what is ::Class exactly?

Abolfazl B
  • 71
  • 9

1 Answers1

0

Answer:

Using that ::class syntax allows you to declare a class without passing it as a string. When they update ide's it will help to auto fill namespaces which can't be done with a string.

Source Information:

Since PHP 5.5, the class keyword is also used for class name resolution. You can get a string containing the fully qualified name of the ClassName class by using ClassName::class. This is particularly useful with namespaced classes.

Example #10 Class name resolution

<?php
namespace NS {
    class ClassName {
    }

    echo ClassName::class;
}
?>

The above example will output:

NS\ClassName

Note:

The class name resolution using ::class is a compile time transformation. That means at the time the class name string is created no autoloading has happened yet. As a consequence, class names are expanded even if the class does not exist. No error is issued in that case.

Source Link :: Php Manual