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