Explanation of the meaning of the range parsing operator (: :) in PHP _ PHP Tutorial

Source: Internet
Author: User
Description of the meaning of the range resolution operator (: :) of PHP. Today I see several symbols about PHP. One is @, which is added before a variable to suppress the error reported by the PHP interpreter. that is to say, the error is not displayed even if an error occurs. There are also several symbols about PHP today. One is @, which is added before a variable to suppress the error reported by the PHP interpreter. that is to say, the error is not displayed even if an error occurs.
There is also a more important symbol PHP's range parsing operator (::)
Functions in the category class or functions and variables in the base class are very useful without declaring any instances. The operator is used in this case.

The code is as follows:


Class {
Function example (){
Echo "I am the original function A: example ().
\ N ";
}
}
Class B extends {
Function example (){
Echo "I am the redefined function B: example ().
\ N ";
A: example ();
}
}
// Class A has no object, which will output
// I am the original function A: example ().

A: example ();
// Create a class B object
$ B = new B;
// This will output
// I am the redefined function B: example ().

// I am the original function A: example ().

$ B-> example ();
?>


The above example calls the function example () of Class A, but there is no object of Class A, so you cannot use $ a-> example () or call example () in a similar way (). Instead, we call example () as a class function, that is, it is called as a class function, rather than any object of the class.
There are class functions, but no class variables. In fact, there is no object at all when calling a function. Therefore, a class function can use no objects (but local or global variables can be used), and $ this variable is not used at all.
In the above example, class B redefined the function example (). The original defined function example () in Class A will be blocked and will no longer take effect unless the: operator is used to access the example () function in Class. For example, A: example () (in fact, it should be written as parent: example (). The next chapter introduces this content ).
In this case, the current object may have an object variable. Therefore, you can use $ this and object variables within the object function.

Bytes. One is @, which is added before a variable to suppress the error reported by the PHP interpreter. that is to say, the error is not displayed even if an error occurs. Another one...

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.