Php novice: I am a beginner in the background management system. what does this sentence mean? What do the two colons mean? I am a newbie and want to explain it clearly.
Reply to discussion (solution)
Manual:
Scope resolution operator (::)
Note:
The following content is only valid in PHP 4 and later versions.
Sometimes, 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.
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.
Manual:
Range resolution operator (::)
The range resolution operator (also known as Paamayim nekudow.im) 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 the class.
When you access these static members, methods, and constants outside the class, you must use the class name.
It seems strange to select Paamayim nekudow.im as the name of this operator. However, this is the decision made by the Zend Development team when writing Zend Engine 0.5 (used in PHP 3. In fact, this word is a double colon in Hebrew.
Example #1 used outside the class: operator
Class MyClass {
Const CONST_VALUE = 'a constant value ';
}
Echo MyClass: CONST_VALUE;
?>
The special keywords self and parent are used to access members or methods within the class.
Example #2: from inside the class definition
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: doubleColon ();
?>
When a subclass overrides the methods in its parent class, PHP will no longer execute the override methods in its parent class until these methods are called in the subclass. This mechanism also applies to constructor and Destructor, overload and magic functions.
Example #3 call the method of the parent class
Class MyClass
{
Protected function myFunc (){
Echo "MyClass: myFunc () \ n ";
}
}
Class OtherClass extends MyClass
{
// Override the methods in the parent class
Public function myFunc ()
{
// But you can still call the overwritten method
Parent: myFunc ();
Echo "OtherClass: myFunc () \ n ";
}
}
$ Class = new OtherClass ();
$ Class-> myFunc ();
?>
What does the entire sentence mean?
Call the WirteLog static method of the Log object and pass the 7 and $ notice parameters to the past.