Php functions, classes and objects, encapsulation, inheritance of classes, static methods of classes, static properties 1. Functions & #160; & #160; & #160; php built-in functions can be used directly. If php extensions are not installed, you can & #160; & #160; & #160; UDF function name functiondump ($ varnull) {php functions, classes and objects, class encapsulation, inheritance, class static methods, static attributes
1. Functions
Php built-in functions can be used directly. If php extensions are not installed
Custom functions
// Function name function dump ($ var = null) {// Default expenditure parameter value echo''; Var_dump ($ var );}
2. class and object (new Obj)
Private $ eye = 'Big Eyes '; private $ mouth = 'small mouth'; private $ leg = 'long legs '; // Constructor calls public function _ construct () {echo _ CLASS __;} public function run () {echo $ this-> leg ;} // you can use leg (walking), eye (Reading), and mouth (reading) public function study () {echo $ this-> leg, $ this-> eye, $ this-> mouth ;}/// the object $ person = new Person () will become after class new is used; // The output Person $ person-> run (); // output long legs $ person-> study (); // output big legs, big eyes, and small lips
3. class encapsulation (public, protected, private) and inheritance (extends)
// Class inheritance class A {public function help () {echo _ METHOD __;}// declare A private function eat () {echo _ METHOD __;}}// subclass can inherit all public methods and attributes of the parent class, protected methods and attributes, except for private methods // If you want to use them, override class B extends A {public function doSomething () {$ this-> help (); // The method that inherits the parent class is declared as public echo'
'; $ This-> eat (); // because eating is private, the subclass cannot be used. here, an eat method is written in the subclass .} // public function eat () {echo _ METHOD __;}}$ B = new B; $ B-> doSomething ();
// Output result
A: help
B: eat 4. static methods and static attributes of classes
5. static attributes of a class
'; Echo self: $ var; echo'
'; Echo _ METHOD __;} public static function redirect ($ url = '') {echo _ METHOD __;} public static function getCurrentUrl () {echo _ METHOD __;}/// declare the METHOD as a static METHOD. you do not need to instantiate (new) objects every time. The operation is convenient, memory saving, and the efficiency is higher. echo Url :: createUrl ($ var = '');