Upgrade to Pro — share decks privately, control downloads, hide ads and more …

PHP v5.3+ Features

Avatar for Michael Bui Michael Bui
September 29, 2014

PHP v5.3+ Features

Overview of main features from PHP v5.3 until current v5.6

Avatar for Michael Bui

Michael Bui

September 29, 2014
Tweet

More Decks by Michael Bui

Other Decks in Programming

Transcript

  1. PHP v5.3 • “ereg” deprecated • SPL always enabled •

    Reflection always enabled • Magic methods ◦ __invoke() ◦ __callStatic() • Performance improved
  2. PHP v5.3 • Namespace ◦ PSR-0 ◦ Composer ◦ For

    classes, functions and constants • Import classes ◦ “use” keyword ◦ relative & absolute namespaces • Closures
  3. PHP v5.4 • PHP_BINARY constant • Array to string conversions

    will trigger a notice • Array callbacks: ◦ [$obj, ‘method’] ◦ [‘ClassName’, ‘method’] • Memory & performance improved
  4. 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...)
  5. 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}()
  6. PHP v5.5 • RegExp /e modifier deprecated • Mysql extension

    officially deprecated • boolval() • empty() support any expression • OPCache built-in
  7. 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
  8. 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()
  9. PHP v5.6 (cont.) • Variadic functions ◦ Referencing ◦ Type

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