Not long ago, PHP just released the first stable version of 5.5, introduced a class-level constant, the name is ' class ' This constant is valid for all classes, and returns the full name of the class.
Copy Code code as follows:
<?php
namespace Vendorpackage;
Class Foo
{
// ...
}
Var_dump (Foo::class);
The above script outputs string (a) "Vendorpackagefoo".
Why to use it
Why do we use one of these constants, and of course not just to get the full name of the class as the example above. We can use __namespace__ to achieve the same effect, and php5.3 can be used:
Copy Code code as follows:
<?php
namespace Vendorpackage;
Class Foo
{
// ...
}
Var_dump (__namespace__. ' Foo ');
However, when you need a fully qualified name, the namespace references the class namespace alias ... And then it gets interesting.
In the following example:
Copy Code code as follows:
<?php
Use Vendorpackagefoo;
Class Footest extends Phpunit_framework_testcase
{
Public Function testbarcanbeprocessed ()
{
$bar = $this->getmock (' Vendorpackagebar ');
$foo = new Foo;
$foo->process ($bar);
// ...
}
}
Copy Code code as follows:
<?php
Use Vendorpackagefoo;
Use Vendorpackagebar;
Class Footest extends Phpunit_framework_testcase
{
Public Function testbarcanbeprocessed ()
{
$bar = $this->getmock (bar::class);
$foo = new Foo;
$foo->process ($bar);
// ...
}
}