Basic accounting exercises and Case Answers PHP Basics: Class and object 4 scope resolution operator::

Source: Internet
Author: User
Tags php basics
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 access members and methods in the overridden class.
When you access these static members, methods, and constants outside of the class, you must use the name of the class.
The Paamayim Nekudotayim in Hebrew is the meaning of double colons.
Use outside of class:: operator
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:
Class Otherclass extends MyClass
{
public static $my _static = ' static var ';
public static function Doublecolon () {
Echo Parent::const_value. "N";
echo Self:: $my _static. "N";
}
}
Otherclass::d Oublecolon ();
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. (Is it nonsense?) No, this is the difference between PHP and other mainstream languages). This mechanism is also used for constructors and destructors, overloads, and magic functions.
Class MyClass
{
protected function MyFunc () {
echo "Myclass::myfunc () n";
}
}
Class Otherclass extends MyClass
{
Overriding methods in a parent class
Public Function MyFunc ()
{
But you can still call methods that have been overridden
Parent::myfunc ();
echo "Otherclass::myfunc () n";
}
}
$class = new Otherclass ();
$class->myfunc ();
--------------------------------------------------------------------------------
?? Focus?? Be sure to use the class name:: Method when accessing static methods or members.
It is also important to note that PHP does not actively invoke the methods of the parent class, including constructors and destructors.
See this text: http://163xiaofan.blog.163.com/blog/static/1713578020061027101820973

The above introduces the basic accounting exercises and case answer PHP basic knowledge: Class and object 4 scope resolution operator::, including the basic accounting exercises and case answers to the content, I hope the PHP tutorial interested in a friend helpful.

  • 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.