bpm-the sixth chapter-Object-oriented PHP

Source: Internet
Author: User

Encapsulation, inheritance, polymorphism

class ClaaName{    //属性声明    //方法声明}    class Employee    {        private $name;        private $title;        protected $wage;        protected function clockIn() {            echo "";        }        protected function clockOut() {            echo "";        }    }
    • Create an object using the New keyword.
    • For properties, it is common practice to declare properties where the class begins.
    • The operator is required to use the property call. $obj->name;
    • When you reference a property in a class that defines a property, you need to display the use this pointer, $this->name;
    • PHP attributes have 5 scopes: public, private, protected, final, static. Can not be displayed when the call to the object itself, if the object can be used directly, called the display call, if it can only be used inside the object, called implicit.
    • Property overloading??!!! __set methods and __ Methods
function __set($propName, $propValue){    $this->$propName = $propValue;}
    • Use the __get method to get the property.
    • Common way:
    class Employee    {        private $name;        public function getName()        {            return $this->name;        }        public function setName($name)        {            $this->name = $name;        }    }
    • Constants can be defined in a class. Used to indicate a value that does not change.
    class mathFunctions    {        const PI = ‘3.14‘;        const E = ‘2.72‘;    }    echo mathFunctions::PI;
    • Methods $obj->methodname ();
    • The PHP method has 6 scopes: public, protected, private, abstract, final, static.
    • Abstract method: Only declared in the parent class, but implemented in subclasses. Only a class that is declared abstract can declare an abstraction method.
    abstract class Employee    {        abstract function hire();        abstract function fire();        abstract function promote();        abstract demoote();    }
# # Constructors and destructors

bpm-the sixth chapter-Object-oriented PHP

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.