Native PHP uses key points to ignore points!

Source: Internet
Author: User


1. When instantiating a class, you need to use:: Call constant
1 class myclass3{2     Const Const_value = ' A constant VALUE '; 3 }45$obj 3new  MyClass3 (); 6 Echo $obj 3:: Const_value;
2. Using static methods or static variables can not be instantiated directly with the class name must use:: Call
1 classMYCLASS42 {3      Public Static $my _static= ' static method variable <br> ';4 5      Public Static functionDoublecolon () {6         EchoSelf::$my _static. "\ n";7     }8 }9 Ten EchoMYCLASS4::$my _static; OneMYCLASS4::d Oublecolon ();
3. Abstract class and abstract method description (1). Abstract classes cannot be instantiated (2). At least one method in an abstract class is declared abstract (3). The abstract method simply declares its invocation method (parameter) and cannot define its specific function implementation. (In simple terms, you can only define the name of an abstract method and not write logic in it) (4). When inheriting an abstract class, the subclass must define all the abstract methods in the parent class (5). When subclasses redefine the parent class abstract method, the declaration level must be greater than or equal to the parent class (6). Subclasses can define optional parameters (7) that do not exist in the parent class. Subordinate knowledge dot curly braces to define the boundary of the variable name "{}"
1 Abstract classAbstractClass2 {3  //forcing subclasses to define these methods4     Abstract protected functionGetValue ();5     Abstract protected functionPrefixvalue ($prefix);6 7     //Common methods (non-abstract methods)8      Public functionPrintOut () {9         Print $this->getvalue (). "\ n";Ten     } One } A  - classConcreteClass1extendsAbstractClass - { the      Public functionGetValue () { -         return"Redefining the abstract method of the parent class"; -     } -  +      Public functionPrefixvalue ($prefix,$xinxin="") { -         return"{$prefix} redefine the abstract method of the parent class {$xinxinhaha; +     } A } at  - $obj 5=NewConcreteClass1 (); - Echo $obj 5-GetValue (); - Echo"<br>"; - Echo $obj 5->prefixvalue ("Add a Parameter", "New parameter");

Native PHP uses key points to ignore points!

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.