I see two different ways of writing. I don't know what the difference between them is? {Code...} I see two different ways of writing. I don't know what the difference is between them?
mysqli->commitmysqli::commit
Reply content:
I see two different ways of writing. I don't know what the difference between them is?
mysqli->commitmysqli::commit
->
Used to accessInstanceGenerally, the left side is a class instance (or$this
), The right side is a function or attribute. arrows can also access static functions through class instances.
::
Used to accessStaticA Member or constant that accesses a member of the parent class. Generally, the left side is a class name, orself
,parent
,static
Keyword. The right side is a static function, static attribute, and constant.
Property; // The function print $ xxoo-> func () to access the instance; // You can also use the instance to access static members. // The Arrow used to access the function, use double colon print $ xxoo-> staticFunc (); print $ xxoo: $ staticProperty; // if you do not use an instance, add the double colon print :: staticFunc (); print A: constValue; // Add the dollar sign print A: $ staticProperty to the static attribute; // inherit class Aclass B extends A {// overwrite the attributes of the parent class public $ property = "covered-properties \ n "; // override the static property static public $ staitcProperty = "covered-staitcProperties \ n" of the parent class; // override the function public function func () of the parent class () {// access your attributes print $ this-> property; // access the static attributes inherited from the parent class print self: $ staticProperty; // access your own (static) function print $ this-> staticFunc (); // The print parent: func ();} function that forces the specified access to the parent class (instead of its own ();} // override the static public function staticFunc () of the parent class. {// because no $ this exists, use self to access the static attribute print self: $ staitcProperty ;}} // run the above example $ xxoo = new B; $ xxoo-> func (); B: staticFunc ();
Summary:
Arrow: Accessing attributes and (static) functions through instances
Double Colon: by class name orself
,parent
,static
Keyword, access constant, static attribute, static function
Http://php.net/manual/zh/language.oop...
PHP5.3 addedStatic binding later
Function, and double colons andstatic
The keyword is related. I am learning this .....
mysqli::commit
This is not the case,php
This indicates in the document thatcommit
Yesmysqli
A member method of the object insteadmysqli
Static Method of this class