Slide 1

Slide 1 text

PHP v5.3+ FEATURES Michael Bui (FB & TW: MichaelBui2812)

Slide 2

Slide 2 text

PHP v5.3 ● “ereg” deprecated ● SPL always enabled ● Reflection always enabled ● Magic methods ○ __invoke() ○ __callStatic() ● Performance improved

Slide 3

Slide 3 text

PHP v5.3 ● Namespace ○ PSR-0 ○ Composer ○ For classes, functions and constants ● Import classes ○ “use” keyword ○ relative & absolute namespaces ● Closures

Slide 4

Slide 4 text

PHP v5.4 ● PHP_BINARY constant ● Array to string conversions will trigger a notice ● Array callbacks: ○ [$obj, ‘method’] ○ [‘ClassName’, ‘method’] ● Memory & performance improved

Slide 5

Slide 5 text

PHP v5.4 ● Traits ○ “compiler level” copy-n-paste (literally) ○ “insteadof” & “as” to solve collisions ● Closures ○ Support “$this” ○ Re-bind “$this” ● Short echo tags “” always work ● Binary numbers (0b...)

Slide 6

Slide 6 text

PHP v5.4 (Cont.) ● Short array syntax: ○ [‘a’=>1,’b’=>2] === array(‘a’=>1,’b’=>2) ○ Array dereferencing: getArray()[0]; ● Initiation time access ○ (new Classname())->method() ● Dynamic method calls: ○ ClassName::{$var}() ○ (new ClassName())->{$var}()

Slide 7

Slide 7 text

PHP v5.5 ● RegExp /e modifier deprecated ● Mysql extension officially deprecated ● boolval() ● empty() support any expression ● OPCache built-in

Slide 8

Slide 8 text

PHP v5.5 ● “finally” supported ● Fully qualified classname constant ○ ClassName::CLASS ● Literal Dereferencing ○ [‘a’,’b’,’c’][1] will return ‘b’ ● “foreach” support “list()” ○ foreach ($records as list($name, $email)) {} ● Generators & Co-routines

Slide 9

Slide 9 text

PHP v5.6 ● Import functions & constants ○ use function Name\Spaced\method; ○ use const Name\Spaced\CONSTANT; ● Scalar expressions supported in ○ Constants: const FOO = self::BAR . “!”; ○ Class properties: public $a = 1 + 1; ○ Function arguments: function f($a = 1 + 1) {} ○ … ● __debugInfo()

Slide 10

Slide 10 text

PHP v5.6 (cont.) ● Variadic functions ○ Referencing ○ Type hinting ● Argument unpacking ● Exponent operator (**) ● Upload more than 2GB

Slide 11

Slide 11 text

ONE MORE THING...

Slide 12

Slide 12 text

THANK YOU! Michael Bui (FB & TW: MichaelBui2812)