Php v5.3+ features

12

Click here to load reader

Transcript of Php v5.3+ features

Page 1: Php v5.3+ features

PHP v5.3+ FEATURESMichael Bui

(FB & TW: MichaelBui2812)

Page 2: Php v5.3+ features

PHP v5.3

● “ereg” deprecated● SPL always enabled● Reflection always enabled● Magic methods

○ __invoke()○ __callStatic()

● Performance improved

Page 3: Php v5.3+ features

PHP v5.3

● Namespace○ PSR-0○ Composer○ For classes, functions and constants

● Import classes○ “use” keyword○ relative & absolute namespaces

● Closures

Page 4: Php v5.3+ features

PHP v5.4

● PHP_BINARY constant● Array to string conversions will trigger

a notice● Array callbacks:

○ [$obj, ‘method’]○ [‘ClassName’, ‘method’]

● Memory & performance improved

Page 5: Php v5.3+ features

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...)

Page 6: Php v5.3+ features

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}()

Page 7: Php v5.3+ features

PHP v5.5

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

Page 8: Php v5.3+ features

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

Page 9: Php v5.3+ features

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()

Page 10: Php v5.3+ features

PHP v5.6 (cont.)

● Variadic functions○ Referencing○ Type hinting

● Argument unpacking● Exponent operator (**)● Upload more than 2GB

Page 11: Php v5.3+ features

ONE MORE THING...

Page 12: Php v5.3+ features

THANK YOU!Michael Bui

(FB & TW: MichaelBui2812)