PHP recently released the first stable version of 5.5, introduced a class-level constant, the name is ' class ', the constant is valid for all classes, returns the full name of the class.
Copy the Code code as follows:
namespace Vendorpackage;
Class Foo
{
// ...
}
Var_dump (Foo::class);
The above script outputs a string of "Vendorpackagefoo".
Why do you want to use it
Why do we use a constant like this, not just the full name of the class, as in the example above. We can also achieve the same effect using __namespace__, and php5.3 can be used:
Copy the Code code as follows:
namespace Vendorpackage;
Class Foo
{
// ...
}
Var_dump (__namespace__. ' Foo ');
However, when you need to fully qualify the name, the namespace references the class namespace alias ... Then it becomes interesting.
In the following example:
Copy the Code code as follows:
Use Vendorpackagefoo;
Class Footest extends Phpunit_framework_testcase
{
Public Function testbarcanbeprocessed ()
{
$bar = $this->getmock (' Vendorpackagebar ');
$foo = new Foo;
$foo->process ($bar);
// ...
}
}
Copy the Code code as follows:
Use Vendorpackagefoo;
Use Vendorpackagebar;
Class Footest extends Phpunit_framework_testcase
{
Public Function testbarcanbeprocessed ()
{
$bar = $this->getmock (bar::class);
$foo = new Foo;
$foo->process ($bar);
// ...
}
}
http://www.bkjia.com/PHPjc/313492.html www.bkjia.com true http://www.bkjia.com/PHPjc/313492.html techarticle PHP recently released the first stable version of 5.5, introduced a class-level constant, the name is ' class ', the constant is valid for all classes, returns the full name of the class. Copy Code Code ...