PHP Object-oriented static and abstract, interface

Source: Internet
Author: User

Static also includes: Ordinary member: A normal member is a static member of an object: A static member is a keyword that belongs to a class:StaticThe self keyword: represents the class inside a class, without adding $ in the static method cannot call the ordinary member in the ordinary method can call the static

Example:classfenbi{ Public $length; The length of the chalk Public Static $color; The color of the chalkStatic functionShow () {Echo"Chalk color is:". Self::$color; } functionXianshi () {Echo"Show:". Self::$color; }}$f=NewFenbi (); Create an object first$f-length; Use object to call ordinary member Fenbi::$color= "Red"; Calling a static member using the class name Fenbi::Show ();$f->xianshi ();
abstract Abstract class keyword abstraction features: Can not be instantiated, can only be inherited purposes: in order to derive subclasses, control subclasses Abstract class dog{    public$name;         function Jiao ()    {        echo "Bark";    }} class extends dog{    }$dnew Dog ();
interface: An extremely abstract class interface cannot contain member variables, only member method member methods can have no function body interface keywords:InterfaceThe class that implements the interface must implement all the methods inside the interfaceInterfaceiusb{functionread (); Read the methodfunctionwrite (); Method of writing} The driver class of the mouseclassMouseImplementsiusb{functionRead () {Echo"Mouse clicked"; }    functionwrite () {Echo"Give the Mouse an instruction"; }} keyboard driver classclassJianpanImplementsiusb{functionRead () {Echo"Keyboard entered the content"; }    functionwrite () {Echo"Give keyboard Instructions"; }}$m=NewMouse ();$m-write ();$j=NewJianpan ();$j-read (); API interface for common interface

PHP Object-oriented static and abstract, interface

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.