Added improvements and additional content in the programming paradigms section.

This commit is contained in:
Jeremy Lindblom
2012-07-18 07:40:18 -07:00
parent 6940a31002
commit 2d59716fae

View File

@@ -4,18 +4,21 @@ isChild: true
## Programming Paradigms
PHP is a flexible, dynamic language that supports a variety of programming techniques. It has evolved dramatically over the years,
notably adding a solid object-oriented model in PHP 5.0 (2004), anonymous functions and namespaces in PHP 5.3 (2009), and traits in
PHP 5.4 (2012).
PHP is a flexible, dynamic language that supports a variety of programming techniques. It has evolved dramatically over
the years, notably adding a solid object-oriented model in PHP 5.0 (2004), anonymous functions and namespaces in PHP
5.3 (2009), and traits in PHP 5.4 (2012).
### 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 Traits][traits]
### 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 %}
<?php
@@ -27,13 +30,20 @@ $greet = function($name)
$greet('World');
{% 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]
### Meta Programming
Ruby developers often say that PHP is lacking `method_missing`, but it is available as `__call()`. There are many Magic Methods available
like `__get()`, `__set()`, `__clone()`, `__toString()`, etc.
PHP supports various forms of meta programming through mechanisms like the Reflection API and Magic Methods. There are
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 Reflection][reflection]
@@ -42,6 +52,8 @@ like `__get()`, `__set()`, `__clone()`, `__toString()`, etc.
[overloading]: http://uk.php.net/manual/en/language.oop5.overloading.php
[oop]: http://www.php.net/manual/en/language.oop5.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
[reflection]: http://www.php.net/manual/en/intro.reflection.php
[traits]: http://www.php.net/traits