Usage of class alias in php5.3 _ PHP Tutorial

Source: Internet
Author: User
The usage of the class alias in php5.3. In PHP5.3, if you want to introduce some classes with a long name, it will be difficult to write. in this case, you can use the class alias of PHP5.3, for example: classIrrational_Long in PHP 5.3, if you want to introduce some classes with a long name, it will be difficult to write. at this time
You can use the alias of PHP 5.3 class, for example:

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 obtain 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 directly use the alias class in the FUNCTION, for example:
Class TestClass
{
Public function doSomethingWithShortAliasInstance (ShortAlias $ B ){}
}
Class_alias (Irrational_Long_Class_Name, ShortAlias );
$ AInstanceWithAlias = new ShortAlias ();
$ TestClassInstance = new TestClass ();
$ TestClassInstance-> doSomethingWithShortAliasInstance ($ aInstanceWithAlias );

In example 5.3, if you want to introduce some classes whose names are long enough, it will be difficult to write them. in this case, you can use the class alias of PHP 5.3, for example: class Irrational_Long...

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.