In PHP 5.3, if you want to introduce some classes with very long names, it will be more troublesome to write. At this time,
can use the usage of class aliases in PHP 5.3. Examples are as follows:
class Irrational_Long_Class_Name
{
// empty class
}
class_alias(Irrational_Long_Class_Name, ShortAlias);
$shortAliasInstance = new ShortAlias();
var_dump( $shortAliasInstance instanceof Irrational_Long_Class_Name);
# true
var_dump( $shortAliasInstance instanceof ShortAlias);
# true
You can use get_class() to get the original real class name, for example:
class Irrational_Long_Class_Name
{
public function getClass()
{
print get_class();
}
}
class_alias(Irrational_Long_Class_Name, ShortAlias);
$aInstanceWithAlias = new ShortAlias();
$aInstanceWithAlias->getClass();
# Irrational_Long_Class_Name
print get_class($aInstanceWithAlias);
# Irrational_Long_Class_Name
You can also use alias classes directly in FUNCTION, such as:
class TestClass
{
public function doSomethingWithShortAliasInstance(ShortAlias $b) { }
}
class_alias( Irrational_Long_Class_Name, ShortAlias);
$aInstanceWithAlias = new ShortAlias();
$testClassInstance = new TestClass();
$testClassInstance->doSomethingWithShortAliasInstance($aInstanceWithAlias);