mirror of
https://github.com/codeguy/php-the-right-way.git
synced 2025-08-06 14:06:34 +02:00
Some examples and notes for programming paradigms.
This commit is contained in:
@@ -4,7 +4,9 @@ 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
|
||||
|
||||
@@ -13,15 +15,31 @@ PHP is a flexible, dynamic language that supports a variety of programming techn
|
||||
|
||||
### Functional Programming
|
||||
|
||||
PHP has had annonymous functions since PHP 5.3:
|
||||
|
||||
{% highlight php %}
|
||||
<?php
|
||||
$greet = function($name)
|
||||
{
|
||||
print("Hello {$name}");
|
||||
};
|
||||
|
||||
$greet('World');
|
||||
{% endhighlight %}
|
||||
|
||||
* [Read about Anonymous functions][anonymous-functions]
|
||||
* [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.
|
||||
|
||||
* [Read about Magic Methods][magic-methods]
|
||||
* [Read about Reflection][reflection]
|
||||
|
||||
[namespaces]: http://php.net/manual/en/language.namespaces.php
|
||||
[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
|
||||
[magic-methods]: http://php.net/manual/en/language.oop5.magic.php
|
||||
|
Reference in New Issue
Block a user