Php functions, classes and objects, class encapsulation, inheritance, class static methods, static attributes, php static _ PHP Tutorial

Source: Internet
Author: User
Php functions, classes and objects, class encapsulation, inheritance, class static methods, static attributes, php static. Php functions, classes and objects, class encapsulation, inheritance, class static methods, static attributes, php static 1, function php built-in functions can be used directly, if php extensions are not installed, php functions, classes and objects, and classes can be encapsulated, inherited, static methods, static attributes of classes, and php 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 = '');

Handler 1. functions built-in php functions can be directly used. If php extensions are not installed, you can...

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.