PHP: Difference between revisions
| Line 50: | Line 50: | ||
==PHP Standard Recommendation (PSR)== | ==PHP Standard Recommendation (PSR)== | ||
* [https://www.php-fig.org/psr/psr-1/ PSR-1] | |||
** each sub-word should be capitalised in both instances, with classes having an initial upper-case letter (StudlyCaps) and methods an initial lower-case letter (camelCase) | |||
** Class constants MUST be declared in all upper case with underscore separators | |||
* [https://www.php-fig.org/psr/psr-2/ PSR-2] | |||
* [https://www.php-fig.org/psr/psr-4/ PSR-4] | |||
==PDO== | ==PDO== | ||
Revision as of 10:11, 12 February 2019
Comments
// single line /* multiple line */
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.
PHP Standard Recommendation (PSR)
- PSR-1
- each sub-word should be capitalised in both instances, with classes having an initial upper-case letter (StudlyCaps) and methods an initial lower-case letter (camelCase)
- Class constants MUST be declared in all upper case with underscore separators
- PSR-2
- PSR-4
PDO
PHP Data Objects (PDO) is a Database Access Abstraction Layer.
Exceptions
The base Exception class provided in PHP 5 can be extended.
PHPUnit
PHPUnit provides a simple framework for creating a test suite to automate testing of functions and classes.