PHP: Difference between revisions
(→OO) |
(→OO) |
||
| Line 35: | Line 35: | ||
parent::__destruct(); // has to be called explicitly | parent::__destruct(); // has to be called explicitly | ||
} | } | ||
* inheritance | |||
class B extends A | |||
{ | |||
public function __construct() | |||
{ | |||
parent::__construct(); | |||
* trait: a trait is similar to a class, but only intended to group functionality in a fine-grained and consistent way. It is not possible to instantiate a Trait on its own. It is an addition to traditional inheritance and enables horizontal composition of behavior; that is, the application of class members without requiring inheritance. | * trait: a trait is similar to a class, but only intended to group functionality in a fine-grained and consistent way. It is not possible to instantiate a Trait on its own. It is an addition to traditional inheritance and enables horizontal composition of behavior; that is, the application of class members without requiring inheritance. | ||
==Resources== | ==Resources== | ||
* http://php.net/manual/en/ | * http://php.net/manual/en/ | ||
Revision as of 22:28, 16 August 2018
Functions
- function arguments:
- bool
- int
- float
- string
- array
- callable
- self
- iterable
- object
- class
- interface
OO
- namespace?
- interface?
- self?
- method
- $this?
- use?
- annotations?
- visibility:
- private: only in this class
- protected: only in derived classes
- public: everywhere
- ctor
function __construct() {
parent::__construct(); // has to be called explicitly
...
}
There can only be one ctor which can have function parameters.
- dtor
function __destruct() {
parent::__destruct(); // has to be called explicitly
}
- inheritance
class B extends A
{
public function __construct()
{
parent::__construct();
- trait: a trait is similar to a class, but only intended to group functionality in a fine-grained and consistent way. It is not possible to instantiate a Trait on its own. It is an addition to traditional inheritance and enables horizontal composition of behavior; that is, the application of class members without requiring inheritance.