mirror of
https://github.com/codeguy/php-the-right-way.git
synced 2025-08-07 14:36:29 +02:00
Added improvements and additional content in the programming paradigms section.
This commit is contained in:
@@ -4,18 +4,21 @@ isChild: true
|
|||||||
|
|
||||||
## Programming Paradigms
|
## Programming Paradigms
|
||||||
|
|
||||||
PHP is a flexible, dynamic language that supports a variety of programming techniques. It has evolved dramatically over the years,
|
PHP is a flexible, dynamic language that supports a variety of programming techniques. It has evolved dramatically over
|
||||||
notably adding a solid object-oriented model in PHP 5.0 (2004), anonymous functions and namespaces in PHP 5.3 (2009), and traits in
|
the years, notably adding a solid object-oriented model in PHP 5.0 (2004), anonymous functions and namespaces in PHP
|
||||||
PHP 5.4 (2012).
|
5.3 (2009), and traits in PHP 5.4 (2012).
|
||||||
|
|
||||||
### Object-oriented Programming
|
### Object-oriented Programming
|
||||||
|
|
||||||
|
PHP has a very complete set of object-oriented programming features including support for classes, abstract classes,
|
||||||
|
interfaces, inheritence, constructors, cloning, exceptions, and more.
|
||||||
|
|
||||||
* [Read about Object-oriented PHP][oop]
|
* [Read about Object-oriented PHP][oop]
|
||||||
* [Read about Traits][traits]
|
* [Read about Traits][traits]
|
||||||
|
|
||||||
### Functional Programming
|
### Functional Programming
|
||||||
|
|
||||||
PHP has had anonymous functions since PHP 5.3:
|
PHP has had support for anonymous functions and closures since PHP 5.3:
|
||||||
|
|
||||||
{% highlight php %}
|
{% highlight php %}
|
||||||
<?php
|
<?php
|
||||||
@@ -27,13 +30,20 @@ $greet = function($name)
|
|||||||
$greet('World');
|
$greet('World');
|
||||||
{% endhighlight %}
|
{% endhighlight %}
|
||||||
|
|
||||||
* [Read about Anonymous functions][anonymous-functions]
|
PHP 5.4 added the ability to bind closures to an object's scope and also improved support for callables such that they
|
||||||
|
can be used interchangeably with anonymous functions in almost all cases.
|
||||||
|
|
||||||
|
* [Read about Anonymous Functions][anonymous-functions]
|
||||||
|
* [Read about the Closure class][closure-class]
|
||||||
|
* [Read about Callables][callables]
|
||||||
* [Read about dynamically invoking functions with `call_user_func_array`][call-user-func-array]
|
* [Read about dynamically invoking functions with `call_user_func_array`][call-user-func-array]
|
||||||
|
|
||||||
### Meta Programming
|
### Meta Programming
|
||||||
|
|
||||||
Ruby developers often say that PHP is lacking `method_missing`, but it is available as `__call()`. There are many Magic Methods available
|
PHP supports various forms of meta programming through mechanisms like the Reflection API and Magic Methods. There are
|
||||||
like `__get()`, `__set()`, `__clone()`, `__toString()`, etc.
|
many Magic Methods available like `__get()`, `__set()`, `__clone()`, `__toString()`, `__invoke()`, etc. that allow
|
||||||
|
developers to hook into class behavior. Ruby developers often say that PHP is lacking `method_missing`, but it is
|
||||||
|
available as `__call()` and `__callStatic()`.
|
||||||
|
|
||||||
* [Read about Magic Methods][magic-methods]
|
* [Read about Magic Methods][magic-methods]
|
||||||
* [Read about Reflection][reflection]
|
* [Read about Reflection][reflection]
|
||||||
@@ -42,6 +52,8 @@ like `__get()`, `__set()`, `__clone()`, `__toString()`, etc.
|
|||||||
[overloading]: http://uk.php.net/manual/en/language.oop5.overloading.php
|
[overloading]: http://uk.php.net/manual/en/language.oop5.overloading.php
|
||||||
[oop]: http://www.php.net/manual/en/language.oop5.php
|
[oop]: http://www.php.net/manual/en/language.oop5.php
|
||||||
[anonymous-functions]: http://www.php.net/manual/en/functions.anonymous.php
|
[anonymous-functions]: http://www.php.net/manual/en/functions.anonymous.php
|
||||||
|
[closure-class]: http://php.net/manual/en/class.closure.php
|
||||||
|
[callables]: http://php.net/manual/en/language.types.callable.php
|
||||||
[magic-methods]: http://php.net/manual/en/language.oop5.magic.php
|
[magic-methods]: http://php.net/manual/en/language.oop5.magic.php
|
||||||
[reflection]: http://www.php.net/manual/en/intro.reflection.php
|
[reflection]: http://www.php.net/manual/en/intro.reflection.php
|
||||||
[traits]: http://www.php.net/traits
|
[traits]: http://www.php.net/traits
|
||||||
|
Reference in New Issue
Block a user