method is the function in the class, many times we can not tell the difference between the method and the function, in the process-oriented program design is called functions, in object-oriented function is called a method.
Like properties, the methods of the class also have public,protected and private access control.
The keyword for access control represents the meaning:
Public: Publicly available
Protected: Protected
Private: Private
We can define methods like this:
Class Car {public function GetName () { return ' car '; }?} $car = new car (); Echo $car->getname ();
Statically decorated with keywords, called static methods, static methods do not need to instantiate objects, can be called directly through the class name, the operator is a double colon:.
Class Car {public static function GetName () { return ' car '; }?} Echo Car::getname (); The result is "car"
Methods of defining classes for PHP classes and objects