PHP 5.3: New Language Features
-
Upload
kaplumbaga -
Category
Documents
-
view
224 -
download
0
Transcript of PHP 5.3: New Language Features
-
8/14/2019 PHP 5.3: New Language Features
1/32
PHP 5.3: New Language FeaturesSebastian Bergmann
July 14th 2009
-
8/14/2019 PHP 5.3: New Language Features
2/32
Who I am
Sebastian Bergmann Involved in the PHP
project since 2000
Creator of PHPUnit Co-Founder and
Principal Consultantwith thePHP.cc
http://sebastian-bergmann.de/http://thephp.cc/http://thephp.cc/http://sebastian-bergmann.de/ -
8/14/2019 PHP 5.3: New Language Features
3/32
PHP 5.3
Lambda Functions Closures
Functors
Late Static Binding\ Namespaces
goto
New Language Features
-
8/14/2019 PHP 5.3: New Language Features
4/32
PHP 5.3
New extensions phar, intl, fileinfo
Garbage Collector
MySQL Native Driver Improved Windows support
Other Improvements
-
8/14/2019 PHP 5.3: New Language Features
5/32
PHP 5.3Performance Improvements
PHP 5.0.5 PHP 5.1.6 PHP 5.2.10 PHP 5.3.0
0
10
20
30
-
8/14/2019 PHP 5.3: New Language Features
6/32
Lambda Functions
Anonymous functions that are declared on-the-fly,
can be assigned to a variable,
and passed to other functions
In a nutshell
-
8/14/2019 PHP 5.3: New Language Features
7/32
Lambda FunctionsUsage
-
8/14/2019 PHP 5.3: New Language Features
8/32
Lambda FunctionsUsage
Hello World!
-
8/14/2019 PHP 5.3: New Language Features
9/32
Lambda FunctionsUsage
Hello World!
-
8/14/2019 PHP 5.3: New Language Features
10/32
Lambda FunctionsUsage
Hello World!
-
8/14/2019 PHP 5.3: New Language Features
11/32
Lambda FunctionsUsage Scenarios
Array(
[0] => 4[1] => 19[2] => 22[3] => 78
)
-
8/14/2019 PHP 5.3: New Language Features
12/32
Lambda FunctionsUsage Scenarios
Array(
[0] => 1[1] => 8
[2] => 27[3] => 64[4] => 125
)
-
8/14/2019 PHP 5.3: New Language Features
13/32
Lambda FunctionsPrior to PHP 5.3
-
8/14/2019 PHP 5.3: New Language Features
14/32
Lambda FunctionsPrior to PHP 5.3
-
8/14/2019 PHP 5.3: New Language Features
15/32
Lambda FunctionsPrior to PHP 5.3
-
8/14/2019 PHP 5.3: New Language Features
16/32
Closures
Anonymous functions that are declared on-the-fly,
can be assigned to a variable,
passed to other functions, and remember what happens around them
In a nutshell
-
8/14/2019 PHP 5.3: New Language Features
17/32
ClosuresLexical Variables
Hello World!
-
8/14/2019 PHP 5.3: New Language Features
18/32
ClosuresLexical Variables
Array(
[0] => 101[1] => 102[2] => 103
)
-
8/14/2019 PHP 5.3: New Language Features
19/32
ClosuresY-Combinator
-
8/14/2019 PHP 5.3: New Language Features
20/32
ClosuresLexical Variables with references
11
1
2
-
8/14/2019 PHP 5.3: New Language Features
21/32
ClosuresReflection API
Closure [ function {closure} ] {
@@ /home/sb/closure_reflection.php 2 - 2
- Parameters [2] {Parameter #0 [ $a ]Parameter #1 [ $b ]
}
}
-
8/14/2019 PHP 5.3: New Language Features
22/32
FunctorsIn a nutshell
Allow an object to be invoked or called asif it were an ordinary function
Can be used to implement statefulcallbacks
Also called function objects, functionals orfunctionoids
-
8/14/2019 PHP 5.3: New Language Features
23/32
FunctorsUsage
Example::__invoke
d
-
8/14/2019 PHP 5.3: New Language Features
24/32
Static BindingEarly Static Binding
Base::a
Base::b
d
-
8/14/2019 PHP 5.3: New Language Features
25/32
Static BindingLate Static Binding
Base::a
Child::b
-
8/14/2019 PHP 5.3: New Language Features
26/32
NamespacesDeclaration
a.php
-
8/14/2019 PHP 5.3: New Language Features
27/32
NamespacesFully qualified names
a.php
b.php
N
-
8/14/2019 PHP 5.3: New Language Features
28/32
NamespacesImport from namespace into local scope
a.php
c.php
N
-
8/14/2019 PHP 5.3: New Language Features
29/32
NamespacesImport from namespace into local scope (conflict)
a.php
c.php
Fatal error: Cannot use project\SomeClass as SomeClass because the
name is already in use in /tmp/c.php on line 6
N
-
8/14/2019 PHP 5.3: New Language Features
30/32
NamespacesImport from namespace into local scope with alias
a.php
d.php
Th E d
-
8/14/2019 PHP 5.3: New Language Features
31/32
The End
Thank you for your interest!
These slides will be posted on
http://slideshare.net/sebastian_bergmann
Li
http://slideshare.net/sebastian_bergmannhttp://slideshare.net/sebastian_bergmann -
8/14/2019 PHP 5.3: New Language Features
32/32
License
This presentation material is published under the Attribution-Share Alike 3.0 Unported
license. You are free:
to Share to copy, distribute and transmit the work.
to Remix to adapt the work.
Under the following conditions:
Attribution. You must attribute the work in the manner specified by the author orlicensor (but not in any way that suggests that they endorse you or your use of thework).
Share Alike. If you alter, transform, or build upon this work, you may distribute theresulting work only under the same, similar or a compatible license.
For any reuse or distribution, you must make clear to others the license terms of this
work. Any of the above conditions can be waived if you get permission from the copyright
holder.
Nothing in this license impairs or restricts the author's moral rights.