Learning classes and objects for beginners in PHP (4)

Source: Internet
Author: User
Tags zend

V. Scope resolution operator (::)

The scope resolution operator (also known as Paamayim Nekudotayim) or, more simply, a pair of colons, can be used to access static members, methods, and constants, and can also be used to override members and methods in a class.

When you access these static members, methods, and constants outside of the class, you must use the name of the class.

It seems strange to choose Paamayim Nekudotayim as the name of the operator. However, this is the decision made by the Zend development team when writing Zend Engine 0.5 (used in PHP 3). In fact, the word in Hebrew is the meaning of a double colon.

Example#1 used outside the class:: operator

<? PHP class MyClass {    const const_value = ' A constant VALUE 'echo MyClass:: const_value ;? >

The two special keywords, self and parent, are used to access members or methods within a class.

Example#2:: From inside the class definition

 <? php  class  Otherclass extends   MyClass { public  static   $my _static  = '    static var ' 

When a subclass overrides a method in its parent class, PHP no longer executes methods that have been overridden in the parent class until the methods are called in the subclass. This mechanism is also used for constructors and destructors, overloads, and magic functions.

Example#3 calling the parent class method

<?PHPclassMyClass {protected functionMyFunc () {Echo"Myclass::myfunc () \ n"; } } classOtherclassextendsMyClass {//overriding methods in a parent class     Public functionMyFunc () {//but you can still call methods that have been overriddenParent::MyFunc (); Echo"Otherclass::myfunc () \ n"; } } $class=NewOtherclass ();$class-MyFunc ();?>

Learning classes and objects for beginners in PHP (4)

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.