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

[PHPConf.Asia 2016] Keynote: PHP Is Dead

[PHPConf.Asia 2016] Keynote: PHP Is Dead

In this keynote for PHPConf.Asia we explore the possibility that PHP is a dying language, and how we as a community can change that.

Davey Shafik

August 23, 2016
Tweet

More Decks by Davey Shafik

Other Decks in Programming

Transcript

  1. P H P CO N F. A S I A K E Y N OT E
    CC-BY-ND 2.0: Michaela Loheit

    View full-size slide

  2. h tt p : / /d e v e l o p e r. a ka m a i .co m

    View full-size slide

  3. Let’s start a conversation about
    mental health in tech
    mhprompt.org

    View full-size slide

  4. R E L E A S E M A N A G E R

    View full-size slide

  5. P H P I S D E A D
    CC-BY 2.0: Nana B Agyei

    View full-size slide

  6. S I N G L E - PAG E A P P L I C AT I O N S A R E
    T H E F U T U R E

    View full-size slide

  7. S I N G L E PA G E A P P L I C AT I O N S A R E T H E F U T U R E
    2011 2016
    Source: Google Trends

    View full-size slide

  8. S I N G L E PA G E A P P L I C AT I O N S A R E T H E F U T U R E
    2011 2016
    Source: Google Trends

    View full-size slide

  9. C L I E N T S I D E M VC F R A M E W O R K S A R E
    T H E F U T U R E

    View full-size slide

  10. C L I E N T S I D E M V C F R A M E W O R K S A R E T H E F U T U R E
    2010 2016
    angular react
    Source: Google Trends

    View full-size slide

  11. C L I E N T S I D E M V C F R A M E W O R K S A R E T H E F U T U R E
    2010 2016
    angular react
    Source: Google Trends

    View full-size slide

  12. J AVA S C R I PT I S T H E F U T U R E

    View full-size slide

  13. J AVA S C R I PT I S W I N N I N G
    2004 2016

    View full-size slide

  14. J AVA S C R I PT I S
    2004 2016

    View full-size slide

  15. W H AT A B O U T P H P ?

    View full-size slide

  16. P H P I S
    Source: Google Trends
    2016
    2004

    View full-size slide

  17. P H P I S J AVA S C R I PT
    Source: Google Trends
    2016
    2004

    View full-size slide

  18. N E W L A N G UAG E S A R E W I N N I N G

    View full-size slide

  19. R UST I S W I N N I N G
    2012 2016
    Source: Google Trends

    View full-size slide

  20. R UST I S W I N N I N G
    2012 2016
    Source: Google Trends

    View full-size slide

  21. G O L A N G I S W I N N I N G
    Source: Google Trends
    2010 2016

    View full-size slide

  22. G O L A N G I S W I N N I N G
    2010 2016
    Source: Google Trends

    View full-size slide

  23. G O L A N G V S R UST
    2010 2016
    Golang Rust
    Source: Google Trends

    View full-size slide

  24. G O L A N G V S R UST V S P H P
    2010 2016
    Rust Golang PHP
    Source: Google Trends

    View full-size slide

  25. M AY B E I T ’ S T H E PA R A D I G M ?

    View full-size slide

  26. O BJ E CT O R I E N T E D V S F U N CT I O N A L P R O G R A M M I N G
    2004 2016
    Object-Oriented Functional
    Source: Google Trends

    View full-size slide

  27. O BJ E CT O R I E N T E D V S F U N CT I O N A L P R O G R A M M I N G
    2004 2016
    Object-Oriented Functional
    Source: Google Trends

    View full-size slide

  28. M AY B E I T ’ S T H E S K I L LS E T !

    View full-size slide

  29. F U L L STA C K D E V E LO P E R V S 1 0 X E N G I N E E R
    2010 2016
    Full Stack Developer 10X Engineer
    Source: Google Trends

    View full-size slide

  30. F U L L STA C K D E V E LO P E R V S 1 0 X E N G I N E E R
    2010 2016
    Full Stack Developer 10X Engineer
    Source: Google Trends

    View full-size slide

  31. F U L L STA C K D E V E LO P E R V S 1 0 X E N G I N E E R
    2016
    10X engineer Full Stack Developer PHP Developer
    Source: Google Trends

    View full-size slide

  32. R I P H P ?
    CC-BY 2.0: johnny myreng henriksen

    View full-size slide

  33. W H AT D O E S P R O G R E SS LO O K L I K E ?
    CC-BY 2.0: damon jah

    View full-size slide

  34. P H P U S A G E
    PHP
    ASP.NET
    Java
    Static Files
    Coldfusion
    Ruby
    Other 1%
    0.6%
    0.7%
    1.5%
    2.7%
    15.8%
    82.1%
    Source: w3techs

    View full-size slide

  35. P H P R E L E A S E S
    2
    3
    4
    5
    6
    7
    8
    9
    2012-02
    2012-05
    2012-08
    2012-11
    2013-02
    2013-05
    2013-08
    2013-11
    2014-02
    2014-05
    2014-08
    2014-11
    2015-02
    2015-05
    2015-08
    2015-11
    2016-02
    2016-05
    Source: php-src git repository

    View full-size slide

  36. P H P V E RS I O N US A G E
    PHP 7.x
    PHP 5.x
    PHP 4.x 1.1%
    97.8%
    1.2%
    Source: w3techs

    View full-size slide

  37. CO N T E XT: 1 2 M O N T H S

    View full-size slide

  38. P H P 5 : T H E F I RST 1 2 M O N T H S
    PHP 5.0 Release
    Source: Google Trends

    View full-size slide

  39. P H P 7 : T H E F I RST 1 2 M O N T H S
    PHP 7.0 Release
    Source: Google Trends

    View full-size slide

  40. P H P 7 : T H E F I RST 1 2 M O N T H S
    PHP 7 PHP 5
    Source: Google Trends
    PHP 5.0/7.0 Release

    View full-size slide

  41. T H I R D - PA RTY E CO SYST E M

    View full-size slide

  42. PAC K AG I ST: PA C KA G E S & R E L E A S E S
    0K
    150K
    300K
    450K
    600K
    2011-09
    2011-12
    2012-03
    2012-06
    2012-09
    2012-12
    2013-03
    2013-06
    2013-09
    2013-12
    2014-03
    2014-06
    2014-09
    2014-12
    2015-03
    2015-06
    2015-09
    2015-12
    2016-03
    2016-06
    568K
    105K
    Packages Versions
    Source: Packagist

    View full-size slide

  43. PAC K AG I ST: PA C KA G E I N STA L LS ( AV E R AG E / D AY )
    0M
    45M
    90M
    135M
    180M
    2012-04
    2012-07
    2012-10
    2013-01
    2013-04
    2013-07
    2013-10
    2014-01
    2014-04
    2014-07
    2014-10
    2015-01
    2015-04
    2015-07
    2015-10
    2016-01
    2016-04
    169M
    Source: Packagist

    View full-size slide

  44. P H P : A F R A C TA L O F B A D D E S I G N
    CC-BY 2.0: Ian Baker
    A P R I L 9 T H 2 0 1 2

    View full-size slide

  45. P R E D I CTA B L E & CO N S I ST E N T
    CC-BY-SA: InSapphoWeTrust

    View full-size slide

  46. L AT E STAT I C B I N D I N G

    View full-size slide

  47. U N I F O R M VA R I A B L E SY N TA X

    View full-size slide

  48. L A N G UA G E S P E C I F I C AT I O N

    View full-size slide

  49. CO N C I S E
    CC-BY 2.0: Dean Hochman

    View full-size slide

  50. C LO S U R E S

    View full-size slide

  51. C A L L A B L E S

    View full-size slide

  52. G E N E R ATO RS

    View full-size slide

  53. A N O N Y M O US C L A SS E S

    View full-size slide

  54. R E L I A B L E
    CC-BY 2.0: mpclemens

    View full-size slide

  55. S H A R E D - N OT H I N G A R C H I T E CT U R E

    View full-size slide

  56. P H P- F P M

    View full-size slide

  57. D E B U G G A B L E
    CC-BY-SA 2.0: Peter Grima

    View full-size slide

  58. P H P I S N OT E VO LV I N G
    CC-BY 2.0: Duncan Hull

    View full-size slide

  59. S H O RT E C H O TAG S
    P H P 5 . 4

    View full-size slide

  60. B I N A R Y N U M B E RS
    P H P 5 . 4

    View full-size slide

  61. S H O RT A R R AY SY N TA X
    P H P 5 . 4

    View full-size slide

  62. A R R AY D E R E F E R E N C I N G
    P H P 5 . 4

    View full-size slide

  63. C LO S U R E $ T H I S B I N D I N G
    P H P 5 . 4

    View full-size slide

  64. C A L L A B L E TY P E H I N T
    P H P 5 . 4

    View full-size slide

  65. T R A I TS
    P H P 5 . 4

    View full-size slide

  66. B U I LT I N C L I S E R V E R
    P H P 5 . 4

    View full-size slide

  67. L I ST S U P P O RT I N FO R E A C H
    P H P 5 . 5

    View full-size slide

  68. A R B I T R A R Y E X P R E SS I O N S U P P O RT
    F O R E M P T Y ( )
    P H P 5 . 5

    View full-size slide

  69. ST R I N G /A R R AY D E R E F E R E N C I N G
    P H P 5 . 5

    View full-size slide

  70. F I N A L LY B LO C K S
    P H P 5 . 5

    View full-size slide

  71. E XT/ PA SS W O R D
    P H P 5 . 5

    View full-size slide

  72. G E N E R ATO RS
    P H P 5 . 5

    View full-size slide

  73. L A N G UA G E S P E C I F I C AT I O N
    T H A N K S FAC E B O O K !

    View full-size slide

  74. E X P O N E N T O P E R ATO R ( T _ P O W )
    P H P 5 . 6

    View full-size slide

  75. CO N STA N T S C A L A R E X P R E SS I O N S
    P H P 5 . 6

    View full-size slide

  76. P H P D B G
    P H P 5 . 6

    View full-size slide

  77. I M P O RT F U N CT I O N S / CO N STA N TS
    P H P 5 . 6

    View full-size slide

  78. VA R I A D I CS
    P H P 5 . 6

    View full-size slide

  79. A R G U M E N T U N PAC K I N G ( S P L AT )
    P H P 5 . 6

    View full-size slide

  80. R E M O V E A LT E R N AT I V E P H P TA G S
    P H P 7 . 0

    View full-size slide

  81. R E M O V E P O S I X R E G E X
    P H P 7 . 0

    View full-size slide

  82. R E M O V E E XT/ M YS Q L
    P H P 7 . 0

    View full-size slide

  83. 2 . 4 X FA ST E R
    P H P 7 . 0

    View full-size slide

  84. A BST R ACT SY N TA X T R E E
    P H P 7 . 0

    View full-size slide

  85. U N I F O R M VA R I A B L E SY N TA X
    P H P 7 . 0

    View full-size slide

  86. E N G I N E E XC E PT I O N S
    P H P 7 . 0

    View full-size slide

  87. U N I CO D E E S C A P E SY N TA X
    P H P 7 . 0

    View full-size slide

  88. N U L L COA L E S C E O P E R ATO R
    P H P 7 . 0

    View full-size slide

  89. B I N D C LO S U R E O N C A L L
    P H P 7 . 0

    View full-size slide

  90. G R O U P US E D E C L A R AT I O N S
    P H P 7 . 0

    View full-size slide

  91. G E N E R ATO R D E L E G AT I O N
    P H P 7 . 0

    View full-size slide

  92. G E N E R ATO R R E T U R N VA LU E S
    P H P 7 . 0

    View full-size slide

  93. A N O N Y M O US C L A SS E S
    P H P 7 . 0

    View full-size slide

  94. S C A L A R TY P E H I N TS
    P H P 7 . 0

    View full-size slide

  95. R E T U R N H I N TS
    P H P 7 . 0

    View full-size slide

  96. ST R I CT TY P E S
    P H P 7 . 0

    View full-size slide

  97. S PA C E S H I P O P E R ATO R
    P H P 7 . 0

    View full-size slide

  98. CO M B I N E D CO M PA R I S O N O P E R ATO R
    P H P 7 . 0

    View full-size slide

  99. T H E F U T U R E
    Credit: NASA/KSC

    View full-size slide

  100. TO O F E W A R G U M E N TS E XC E PT I O N

    View full-size slide

  101. TO O F E W A R G U M E N TS E XC E PT I O N
    • Throw an exception when too few arguments are passed to a user
    defined function/method regardless of strict types
    • Backwards compatibility break

    View full-size slide

  102. TO O F E W A R G U M E N TS E XC E PT I O N
    function hello($whom)
    {
    echo "Hello $whom";
    }
    hello();
    1
    2
    3
    4
    5
    6

    View full-size slide

  103. TO O F E W A R G U M E N TS E XC E PT I O N
    function hello($whom)
    {
    echo "Hello $whom";
    }
    hello();
    1
    2
    3
    4
    5
    6

    View full-size slide

  104. function hello($whom)
    {
    echo "Hello $whom";
    }
    hello();
    TO O F E W A R G U M E N TS E XC E PT I O N
    1
    2
    3
    4
    5
    6

    View full-size slide

  105. function hello($whom)
    {
    echo "Hello $whom";
    }
    hello();
    TO O F E W A R G U M E N TS E XC E PT I O N
    1
    2
    3
    4
    5
    6

    View full-size slide

  106. function hello($whom)
    {
    echo "Hello $whom";
    }
    hello();
    TO O F E W A R G U M E N TS E XC E PT I O N
    1
    2
    3
    4
    5
    6

    View full-size slide

  107. function hello($whom)
    {
    echo "Hello $whom";
    }
    hello();
    TO O F E W A R G U M E N TS E XC E PT I O N
    1
    2
    3
    4
    5
    6
    Warning: Missing argument 1 for hello(), called
    in on line 6 and defined in on
    line 1

    View full-size slide

  108. function hello($whom)
    {
    echo "Hello $whom";
    }
    hello();
    TO O F E W A R G U M E N TS E XC E PT I O N
    1
    2
    3
    4
    5
    6
    Notice: Undefined variable: what in on
    line 4
    Hello

    View full-size slide

  109. TO O F E W A R G U M E N TS E XC E PT I O N
    1
    2
    3
    4
    5
    6
    function hello($whom)
    {
    echo "Hello $whom";
    }
    hello();

    View full-size slide

  110. function hello($whom)
    {
    echo "Hello $whom";
    }
    hello();
    TO O F E W A R G U M E N TS E XC E PT I O N
    1
    2
    3
    4
    5
    6
    Fatal error: Uncaught Error: Too few arguments
    to function hello(), 0 passed in on line
    6 and exactly 1 expected in :2

    View full-size slide

  111. TO O F E W A R G U M E N TS E XC E PT I O N
    function hello($whom)
    {
    echo "Hello $whom";
    }
    try {
    hello();
    } catch (\Error $e) {
    // Handle exception
    }
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10

    View full-size slide

  112. TO O F E W A R G U M E N TS E XC E PT I O N
    function hello($whom)
    {
    echo "Hello $whom";
    }
    try {
    hello();
    } catch (\Error $e) {
    // Handle exception
    }
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10

    View full-size slide

  113. function hello($whom)
    {
    echo "Hello $whom";
    }
    try {
    hello();
    } catch (\Error $e) {
    // Handle exception
    }
    TO O F E W A R G U M E N TS E XC E PT I O N
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10

    View full-size slide

  114. function hello($whom)
    {
    echo "Hello $whom";
    }
    try {
    hello();
    } catch (\Error $e) {
    // Handle exception
    }
    TO O F E W A R G U M E N TS E XC E PT I O N
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10

    View full-size slide

  115. function hello($whom, $when)
    {
    echo "Hello $whom, have a good $when";
    }
    try {
    $args = ['World'];
    hello(... $args);
    } catch (\Error $e) {
    // Handle exception
    }
    TO O F E W A R G U M E N TS E XC E PT I O N
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11

    View full-size slide

  116. function hello($whom, $when)
    {
    echo "Hello $whom, have a good $when";
    }
    try {
    $args = ['World'];
    hello(... $args);
    } catch (\Error $e) {
    // Handle exception
    }
    TO O F E W A R G U M E N TS E XC E PT I O N
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11

    View full-size slide

  117. function hello($whom, $when)
    {
    echo "Hello $whom, have a good $when";
    }
    try {
    $args = ['World'];
    hello(... $args);
    } catch (\Error $e) {
    // Handle exception
    }
    TO O F E W A R G U M E N TS E XC E PT I O N
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11

    View full-size slide

  118. N E G AT I V E ST R I N G O F FS E TS

    View full-size slide

  119. N E G AT I V E ST R I N G O F FS E TS
    • Consistently support negative string offsets
    • Similar to substr()
    • In string character accessors
    • Internal functions

    View full-size slide

  120. N E G AT I V E ST R I N G O F FS E TS
    $path = "/path/to/somewhere/";
    if (substr($path, -1) !== '/') {
    $path = substr($path, 0, -1);
    }

    View full-size slide

  121. N E G AT I V E ST R I N G O F FS E TS
    $path = "/path/to/somewhere/";
    if (substr($path, -1) !== '/') {
    $path = substr($path, 0, -1);
    }

    View full-size slide

  122. N E G AT I V E ST R I N G O F FS E TS
    $path = "/path/to/somewhere/";
    if ($path[-1] === '/') {
    $path = substr($path, 0, -1);
    }

    View full-size slide

  123. N E G AT I V E ST R I N G O F FS E TS
    $path = "/path/to/somewhere/";
    if ($path{-1} === '/') {
    $path = substr($path, 0, -1);
    }

    View full-size slide

  124. S E T C H A R A CT E RS
    $string = "abc";
    $string[-2] = "z";
    // $string == "azc"

    View full-size slide

  125. C H E C K L E N GT H
    if (strlen($_POST['password']) < 8) {
    // Do something
    }
    if (!isset($_POST['password'][7])) {
    // Do something
    }
    if (!isset($_POST['password'][-8])) {
    // Do something
    }

    View full-size slide

  126. if (strlen($_POST['password']) < 8) {
    // Do something
    }
    if (!isset($_POST['password'][7])) {
    // Do something
    }
    if (!isset($_POST['password'][-8])) {
    // Do something
    }
    C H E C K L E N GT H

    View full-size slide

  127. if (strlen($_POST['password']) < 8) {
    // Do something
    }
    if (!isset($_POST['password'][7])) {
    // Do something
    }
    if (!isset($_POST['password'][-8])) {
    // Do something
    }
    C H E C K L E N GT H

    View full-size slide

  128. F U N CT I O N S U P P O RT
    strpos()
    stripos()
    substr_count()
    grapheme_strpos()
    grapheme_stripos()
    grapheme_extract()
    iconv_strpos()
    file_get_contents()
    mb_strimwidth()
    mb_ereg_search_setpos()
    mb_strpos()
    mb_stripos()

    View full-size slide

  129. C LO S U R E F R O M C A L L A B L E

    View full-size slide

  130. C LO S U R E F R O M C A L L A B L E
    class Closure {
    public static function fromCallable(callable $callable): Closure

    {

    ...

    }

    }

    View full-size slide

  131. C LO S I N G OV E R S CO P E

    View full-size slide

  132. C LO S I N G O V E R S CO P E
    class Validator {
    public function getValidatorCallback($validationType) {
    if ($validationType == 'email') {
    return [$this, 'emailValidation'];
    }
    return [$this, 'genericValidation'];
    }
    private function emailValidation($userData) {...}
    private function genericValidation($userData) {...}
    }
    $validator = new Validator();
    $callback = $validator->getValidatorCallback('email');
    $callback($userData);

    View full-size slide

  133. C LO S I N G O V E R S CO P E
    class Validator {
    public function getValidatorCallback($validationType) {
    if ($validationType == 'email') {
    return [$this, 'emailValidation'];
    }
    return [$this, 'genericValidation'];
    }
    private function emailValidation($userData) {...}
    private function genericValidation($userData) {...}
    }
    $validator = new Validator();
    $callback = $validator->getValidatorCallback('email');
    $callback($userData);

    View full-size slide

  134. C LO S I N G O V E R S CO P E
    class Validator {
    public function getValidatorCallback($validationType) {
    if ($validationType == 'email') {
    return [$this, 'emailValidation'];
    }
    return [$this, 'genericValidation'];
    }
    private function emailValidation($userData) {...}
    private function genericValidation($userData) {...}
    }
    $validator = new Validator();
    $callback = $validator->getValidatorCallback('email');
    $callback($userData);

    View full-size slide

  135. C LO S I N G O V E R S CO P E
    class Validator {
    public function getValidatorCallback($validationType) {
    if ($validationType == 'email') {
    return [$this, 'emailValidation'];
    }
    return [$this, 'genericValidation'];
    }
    private function emailValidation($userData) {...}
    private function genericValidation($userData) {...}
    }
    $validator = new Validator();
    $callback = $validator->getValidatorCallback('email');
    $callback($userData);

    View full-size slide

  136. C LO S I N G O V E R S CO P E
    class Validator {
    public function getValidatorCallback($validationType) {
    if ($validationType == 'email') {
    return [$this, 'emailValidation'];
    }
    return [$this, 'genericValidation'];
    }
    private function emailValidation($userData) {...}
    private function genericValidation($userData) {...}
    }
    $validator = new Validator();
    $callback = $validator->getValidatorCallback('email');
    $callback($userData);

    View full-size slide

  137. C LO S I N G O V E R S CO P E
    class Validator {
    public function getValidatorCallback($validationType) {
    if ($validationType == 'email') {
    return [$this, 'emailValidation'];
    }
    return [$this, 'genericValidation'];
    }
    private function emailValidation($userData) {...}
    private function genericValidation($userData) {...}
    }
    $validator = new Validator();
    $callback = $validator->getValidatorCallback('email');
    $callback($userData);

    View full-size slide

  138. C LO S I N G O V E R S CO P E
    class Validator {
    public function getValidatorCallback($validationType) {
    if ($validationType == 'email') {
    return [$this, 'emailValidation'];
    }
    return [$this, 'genericValidation'];
    }
    private function emailValidation($userData) {...}
    private function genericValidation($userData) {...}
    }
    $validator = new Validator();
    $callback = $validator->getValidatorCallback('email');
    $callback($userData);

    View full-size slide

  139. C LO S I N G O V E R S CO P E
    class Validator {
    public function getValidatorCallback($validationType) {
    if ($validationType == 'email') {
    return [$this, 'emailValidation'];
    }
    return [$this, 'genericValidation'];
    }
    private function emailValidation($userData) {...}
    private function genericValidation($userData) {...}
    }
    $validator = new Validator();
    $callback = $validator->getValidatorCallback('email');
    $callback($userData);

    View full-size slide

  140. C LO S I N G O V E R S CO P E
    class Validator {
    public function getValidatorCallback($validationType) {
    if ($validationType == 'email') {
    return [$this, 'emailValidation'];
    }
    return [$this, 'genericValidation'];
    }
    private function emailValidation($userData) {...}
    private function genericValidation($userData) {...}
    }
    $validator = new Validator();
    $callback = $validator->getValidatorCallback('email');
    $callback($userData);

    View full-size slide

  141. C LO S I N G O V E R S CO P E
    class Validator {
    public function getValidatorCallback($validationType) {
    if ($validationType == 'email') {
    return [$this, 'emailValidation'];
    }
    return [$this, 'genericValidation'];
    }
    private function emailValidation($userData) {...}
    private function genericValidation($userData) {...}
    }
    $validator = new Validator();
    $callback = $validator->getValidatorCallback('email');
    $callback($userData);

    View full-size slide

  142. C LO S I N G O V E R S CO P E
    Fatal error: Uncaught Error: Call to private
    method Validator::emailValidation() from
    context '' in :

    View full-size slide

  143. C LO S I N G O V E R S CO P E
    class Validator {
    public function getValidatorCallback($validationType) {
    if ($validationType == 'email') {
    return [$this, 'emailValidation'];
    }
    return [$this, 'genericValidation'];
    }
    private function emailValidation($userData) {...}
    private function genericValidation($userData) {...}
    }
    $validator = new Validator();
    $callback = $validator->getValidatorCallback('email');
    $callback($userData);

    View full-size slide

  144. C LO S I N G O V E R S CO P E
    class Validator {
    public function getValidatorCallback($validationType) {
    if ($validationType == 'email') {
    return [$this, 'emailValidation'];
    }
    return [$this, 'genericValidation'];
    }
    private function emailValidation($userData) {...}
    private function genericValidation($userData) {...}
    }
    $validator = new Validator();
    $callback = $validator->getValidatorCallback('email');
    $callback($userData);

    View full-size slide

  145. C LO S I N G O V E R S CO P E
    class Validator {
    public function getValidatorCallback($validationType) {
    if ($validationType == 'email') {
    return [$this, 'emailValidation'];
    }
    return [$this, 'genericValidation'];
    }
    public function emailValidation($userData) {...}
    public function genericValidation($userData) {...}
    }
    $validator = new Validator();
    $callback = $validator->getValidatorCallback('email');
    $callback($userData);

    View full-size slide

  146. C LO S I N G O V E R S CO P E
    class Validator {
    public function getValidatorCallback($validationType) {
    if ($validationType == 'email') {
    return [$this, 'emailValidation'];
    }
    return [$this, 'genericValidation'];
    }
    public function emailValidation($userData) {...}
    public function genericValidation($userData) {...}
    }
    $validator = new Validator();
    $callback = $validator->getValidatorCallback('email');
    $callback($userData);

    View full-size slide

  147. C LO S I N G O V E R S CO P E
    class Validator {
    public function getValidatorCallback($validationType) {
    if ($validationType == 'email') {
    return [$this, 'emailValidation'];
    }
    return [$this, 'genericValidation'];
    }
    private function emailValidation($userData) {...}
    private function genericValidation($userData) {...}
    }
    $validator = new Validator();
    $callback = $validator->getValidatorCallback('email');
    $callback($userData);

    View full-size slide

  148. C LO S I N G O V E R S CO P E
    class Validator {
    public function getValidatorCallback($validationType) {
    if ($validationType == 'email') {
    return Closure::fromCallable([$this, 'emailValidation']);
    }
    return Closure::fromCallable([$this, 'genericValidation']);
    }
    private function emailValidation($userData) {...}
    private function genericValidation($userData) {...}
    }
    $validator = new Validator();
    $callback = $validator->getValidatorCallback('email');
    $callback($userData);

    View full-size slide

  149. C LO S I N G O V E R S CO P E
    class Validator {
    public function getValidatorCallback($validationType) {
    if ($validationType == 'email') {
    return Closure::fromCallable([$this, 'emailValidation']);
    }
    return Closure::fromCallable([$this, 'genericValidation']);
    }
    private function emailValidation($userData) {...}
    private function genericValidation($userData) {...}
    }
    $validator = new Validator();
    $callback = $validator->getValidatorCallback('email');
    $callback($userData);

    View full-size slide

  150. B E T T E R E R R O R H A N D L I N G

    View full-size slide

  151. B E T T E R E R R O R H A N D L I N G
    class Validator {
    public function getValidatorCallback($validationType) {
    if ($validationType == 'email') {
    return Closure::fromCallable([$this, 'emailValidation']);
    }
    return Closure::fromCallable([$this, 'genericValidation']);
    }
    private function emailValidation($userData) {...}
    private function genericValidation($userData) {...}
    }
    $validator = new Validator();
    $callback = $validator->getValidatorCallback('email');
    $callback($userData);

    View full-size slide

  152. B E T T E R E R R O R H A N D L I N G
    class Validator {
    public function getValidatorCallback($validationType) {
    if ($validationType == 'email') {
    return Closure::fromCallable([$this, 'emailValdation']);
    }
    return Closure::fromCallable([$this, 'genericValidation']);
    }
    private function emailValidation($userData) {...}
    private function genericValidation($userData) {...}
    }
    $validator = new Validator();
    $callback = $validator->getValidatorCallback('email');
    $callback($userData);

    View full-size slide

  153. B E T T E R E R R O R H A N D L I N G
    TypeError: Failed to create closure from
    callable: class 'Validator' does not have a
    method 'emailValdation' in :

    View full-size slide

  154. B E T T E R E R R O R H A N D L I N G
    TypeError: Failed to create closure from
    callable: function 'foo' not found or invalid
    function name in :

    View full-size slide

  155. C L A SS CO N STA N T V I S I B I L I TY

    View full-size slide

  156. C L A SS CO N STA N T V I S I B I L I TY
    class MyClass {
    const MY_CONSTANT = 0;
    const MY_OTHER_CONSTANT = 1;
    const MY_FAVORITE_CONSTANT = 2;
    const FOO = 1, BAR = 2;
    }

    View full-size slide

  157. C L A SS CO N STA N T V I S I B I L I TY
    class MyClass {
    public const MY_CONSTANT = 0;
    protected const MY_OTHER_CONSTANT = 1;
    private const MY_FAVORITE_CONSTANT = 2;
    private const FOO = 1, BAR = 2;
    }

    View full-size slide

  158. C L A SS CO N STA N T V I S I B I L I TY
    class MyClass {
    public const MY_CONSTANT = 0;
    protected const MY_OTHER_CONSTANT = 1;
    private const MY_FAVORITE_CONSTANT = 2;
    private const FOO = 1, BAR = 2;
    }

    View full-size slide

  159. C L A SS CO N STA N T V I S I B I L I TY
    class MyClass {
    public const MY_CONSTANT = 0;
    protected const MY_OTHER_CONSTANT = 1;
    private const MY_FAVORITE_CONSTANT = 2;
    private const FOO = 1, BAR = 2;
    }

    View full-size slide

  160. C L A SS CO N STA N T V I S I B I L I TY
    class MyClass {
    public const MY_CONSTANT = 0;
    protected const MY_OTHER_CONSTANT = 1;
    private const MY_FAVORITE_CONSTANT = 2;
    private const FOO = 1, BAR = 2;
    }

    View full-size slide

  161. C L A SS CO N STA N T V I S I B I L I TY
    class MyClass {
    public const MY_CONSTANT = 0;
    protected const MY_OTHER_CONSTANT = 1;
    private const MY_FAVORITE_CONSTANT = 2;
    private const FOO = 1, BAR = 2;
    }

    View full-size slide

  162. I N T E R FA C E CO N STA N T V I S I B I L I TY
    interface MyInterface {
    public const MY_CONSTANT = 0;
    protected const MY_OTHER_CONSTANT = 1;
    private const MY_FAVORITE_CONSTANT = 2;
    private const FOO = 1, BAR = 2;
    }

    View full-size slide

  163. E N H A N C E M E N TS TO R E F L E CT I O N
    • Added ReflectionClass->getReflectionConstant()
    • Added ReflectionClass->getReflectionConstants()
    • Both return ReflectionClassConstant instances

    View full-size slide

  164. E N H A N C E M E N TS TO R E F L E CT I O N
    class ReflectionClassConstant {
    public function getName() { }
    public function getValue() { }
    public function isPublic() { }
    public function isPrivate() { }
    public function isProtected() { }
    public function getModifiers() { }
    public function getDeclaringClass() { }
    public function getDocComment() { }
    }

    View full-size slide

  165. C ATC H I N G M U LT I P L E E XC E PT I O N S

    View full-size slide

  166. C ATC H I N G M U LT I P L E E XC E PT I O N S
    try {
    ...
    } catch (\PDOException $e) {
    \My\App::renderError(500);
    } catch (\My\RequestException $e) {
    \My\App::renderError(500);
    } catch (\My\RequestMethodException $e) {
    \My\App::renderError(405);
    }

    View full-size slide

  167. C ATC H I N G M U LT I P L E E XC E PT I O N S
    try {
    ...
    } catch (\PDOException $e) {
    \My\App::renderError(500);
    } catch (\My\RequestException $e) {
    \My\App::renderError(500);
    } catch (\My\RequestMethodException $e) {
    \My\App::renderError(405);
    }

    View full-size slide

  168. C ATC H I N G M U LT I P L E E XC E PT I O N S
    try {
    ...
    } catch (\PDOException $e) {
    \My\App::renderError(500);
    } catch (\My\RequestException $e) {
    \My\App::renderError(500);
    } catch (\My\RequestMethodException $e) {
    \My\App::renderError(405);
    }

    View full-size slide

  169. C ATC H I N G M U LT I P L E E XC E PT I O N S
    try {
    ...
    } catch (\PDOException $e) {
    \My\App::renderError(500);
    } catch (\My\RequestException $e) {
    \My\App::renderError(500);
    } catch (\My\RequestMethodException $e) {
    \My\App::renderError(405);
    }

    View full-size slide

  170. C ATC H I N G M U LT I P L E E XC E PT I O N S
    try {
    ...
    } catch (\PDOException $e) {
    \My\App::renderError(500);
    } catch (\My\RequestException $e) {
    \My\App::renderError(500);
    } catch (\My\RequestMethodException $e) {
    \My\App::renderError(405);
    }

    View full-size slide

  171. C ATC H I N G M U LT I P L E E XC E PT I O N S
    try {
    ...
    } catch (\PDOException $e) {
    \My\App::renderError(500);
    } catch (\My\RequestException $e) {
    \My\App::renderError(500);
    } catch (\My\RequestMethodException $e) {
    \My\App::renderError(405);
    }

    View full-size slide

  172. C ATC H I N G M U LT I P L E E XC E PT I O N S
    try {
    ...
    } catch (\PDOException | \My\RequestException $e) {
    \My\App::renderError(500);
    } catch (\My\RequestMethodException $e) {
    \My\App::renderError(405);
    }

    View full-size slide

  173. C ATC H I N G M U LT I P L E E XC E PT I O N S
    try {
    ...
    } catch (\PDOException | \My\RequestException $e) {
    \My\App::renderError(500);
    } catch (\My\RequestMethodException $e) {
    \My\App::renderError(405);
    }

    View full-size slide

  174. L I S T ( ) I M P R OV E M E N TS

    View full-size slide

  175. S P E C I F Y I N G K E YS I N L I S T ( )

    View full-size slide

  176. S P E C I F Y I N G K E YS I N L I S T ( )
    $coords = [
    'lat' => '1.3521° N',
    'long' => '103.8198° E'
    ];
    list($lat, $long) = $coords;
    var_dump($lat, $long);

    View full-size slide

  177. S P E C I F Y I N G K E YS I N L I S T ( )
    $coords = [
    'lat' => '1.3521° N',
    'long' => '103.8198° E'
    ];
    list($lat, $long) = $coords;
    var_dump($lat, $long);

    View full-size slide

  178. S P E C I F Y I N G K E YS I N L I S T ( )
    $coords = [
    'lat' => '1.3521° N',
    'long' => '103.8198° E'
    ];
    list($lat, $long) = $coords;
    var_dump($lat, $long);

    View full-size slide

  179. S P E C I F Y I N G K E YS I N L I S T ( )
    $coords = [
    'lat' => '1.3521° N',
    'long' => '103.8198° E'
    ];
    list($lat, $long) = $coords;
    var_dump($lat, $long);
    Notice: Undefined offset: 0

    Notice: Undefined offset: 1

    View full-size slide

  180. S P E C I F Y I N G K E YS I N L I S T ( )
    $coords = [
    'lat' => '1.3521° N',
    'long' => '103.8198° E'
    ];
    list($lat, $long) = $coords;
    var_dump($lat, $long);

    View full-size slide

  181. S P E C I F Y I N G K E YS I N L I S T ( )
    $coords = [
    'lat' => '1.3521° N',
    'long' => '103.8198° E'
    ];
    list($lat, $long) = $coords;
    var_dump($lat, $long);
    $lat === NULL

    $long === NULL

    View full-size slide

  182. S P E C I F Y I N G K E YS I N L I S T ( )
    $coords = [
    'lat' => '1.3521° N',
    'long' => '103.8198° E'
    ];
    list($lat, $long) = $coords;
    var_dump($lat, $long);

    View full-size slide

  183. S P E C I F Y I N G K E YS I N L I S T ( )
    $coords = [
    'lat' => '1.3521° N',
    'long' => '103.8198° E'
    ];
    list('lat' => $lat, 'long' => $long) = $coords;
    var_dump($lat, $long);

    View full-size slide

  184. S P E C I F Y I N G K E YS I N L I S T ( )
    $coords = [
    'lat' => '1.3521° N',
    'long' => '103.8198° E'
    ];
    list('lat' => $lat, 'long' => $long) = $coords;
    var_dump($lat, $long);

    View full-size slide

  185. S P E C I F Y I N G K E YS I N L I S T ( )
    $coords = [
    'lat' => '1.3521° N',
    'long' => '103.8198° E'
    ];
    list('lat' => $lat, 'long' => $long) = $coords;
    var_dump($lat, $long);
    $lat === '1.3521° N'

    $long === '103.8198° E'

    View full-size slide

  186. S K I P P I N G N U M E R I C K E YS

    View full-size slide

  187. S K I P P I N G N U M E R I C K E YS
    list(
    ,
    $lat,
    $long,
    ,
    ,
    $name
    ) = getLocation();

    View full-size slide

  188. S K I P P I N G N U M E R I C K E YS
    list(
    ,
    $lat,
    $long,
    ,
    ,
    $name
    ) = getLocation();

    View full-size slide

  189. S K I P P I N G N U M E R I C K E YS
    list(
    1 => $lat,
    2 => $long,
    5 => $name
    ) = getLocation();

    View full-size slide

  190. S H O RT L I ST ( ) SY N TA X

    View full-size slide

  191. S H O RT L I ST ( ) SY N TA X
    list('lat' => $lat, 'long' => $long) = $coords;

    View full-size slide

  192. S H O RT L I ST ( ) SY N TA X
    ['lat' => $lat, 'long' => $long] = $coords;

    View full-size slide

  193. S H O RT L I ST ( ) SY N TA X : M U T UA L LY E XC LU S I V E SY N TA X
    // This is not allowed:
    list([$a, $b], [$c, $d]) = [[1, 2], [3, 4]];
    // This is also not allowed:
    [list($a, $b), list($c, $d)] = [[1, 2], [3, 4]];
    // This, however, is allowed:
    [[$a, $b], [$c, $d]] = [[1, 2], [3, 4]];
    // This also:
    list(list($a, $b), list($c, $d)) = [[1, 2], [3, 4]];

    View full-size slide

  194. I T E R A B L E PS U E D OTY P E

    View full-size slide

  195. I T E R A B L E P S U E D OTY P E
    • Similar to callable but values you can foreach, or yield
    • Accepts any array, or object that implements Traversable
    • SPL Iterators
    • Generators
    • Can be used for return value

    View full-size slide

  196. I T E R A B L E P S U E D OTY P E
    function enumerate(iterable $args) {
    foreach ($args as $arg) {
    echo $args;
    }
    }

    View full-size slide

  197. I T E R A B L E P S U E D OTY P E
    function enumerate(iterable $args) {
    foreach ($args as $arg) {
    echo $args;
    }
    }

    View full-size slide

  198. I T E R A B L E P S U E D OTY P E
    function enumerate(iterable $args) {
    foreach ($args as $arg) {
    echo $args;
    }
    }

    View full-size slide

  199. I T E R A B L E P S U E D OTY P E : R E T U R N TY P E
    function compactor(... $args): iterable {
    return $args;
    }

    View full-size slide

  200. I T E R A B L E P S U E D OTY P E : R E T U R N TY P E
    function compactor(... $args): iterable {
    return $args;
    }

    View full-size slide

  201. I T E R A B L E P S U E D OTY P E : R E T U R N TY P E
    function compactor(... $args): iterable {
    return $args;
    }

    View full-size slide

  202. I T E R A B L E P S U E D OTY P E : G E N E R ATO RS
    function compactor(... $args): iterable {
    foreach ($args as $arg) {
    yield $arg;
    }
    }

    View full-size slide

  203. A D D S I S _ I T E R A B L E ( ) F U N CT I O N
    // true
    is_iterable([1, 2, 3]);
    is_iterable(new ArrayIterator([1, 2, 3]));
    is_iterable((function () { yield 1; })());
    // false
    is_iterable(1);
    is_iterable("Hello World");
    is_iterable(new stdClass());

    View full-size slide

  204. V O I D R E T U R N TY P E

    View full-size slide

  205. V O I D R E T U R N TY P E
    • PHP functions implicitly return null
    • There is a semantic difference between returning null, and
    returning nothing (or not returning)
    • Void enforces this behavior
    • Can only be used as a return type
    • Cannot be changed in sub-classes

    View full-size slide

  206. function return_nothing(): void {

    return null;

    }
    V O I D R E T U R N TY P E

    View full-size slide

  207. function return_nothing(): void {

    return null;

    }
    V O I D R E T U R N TY P E

    View full-size slide

  208. function return_nothing(): void {

    return null;

    }
    V O I D R E T U R N TY P E

    View full-size slide

  209. function return_nothing(): void {

    return null;

    }
    V O I D R E T U R N TY P E

    View full-size slide

  210. V O I D R E T U R N TY P E
    function return_nothing(): void {

    return null;

    }
    Fatal error: A void function must not return a
    value (did you mean "return;" instead of
    "return null;"?)

    View full-size slide

  211. V O I D R E T U R N TY P E
    function return_nothing(): void {

    return "nothing";

    }
    Fatal error: A void function must not return a
    value

    View full-size slide

  212. V O I D R E T U R N TY P E
    function return_nothing(): void {

    return;

    }
    // or
    function return_nothing(): void {
    // no return

    }

    View full-size slide

  213. N U L L A B L E TY P E S

    View full-size slide

  214. N U L L A B L E TY P E S
    • Allow specified type, or null
    • Requires an explicit null, doesn’t default to null
    • Works for Arguments & Return Types
    • Prefix type with a ? (question mark)

    View full-size slide

  215. function hello(string $whom)

    {

    echo "Hello " . ($whom ?? "World");

    }
    hello();
    N U L L A B L E TY P E S

    View full-size slide

  216. function hello(string $whom)

    {

    echo "Hello " . ($whom ?? "World");

    }
    hello();
    N U L L A B L E TY P E S

    View full-size slide

  217. function hello(string $whom)

    {

    echo "Hello " . ($whom ?? "World");

    }
    hello();
    N U L L A B L E TY P E S

    View full-size slide

  218. function hello(?string $whom)

    {

    echo "Hello " . ($whom ?? "World");

    }
    hello();
    N U L L A B L E TY P E S

    View full-size slide

  219. function hello(?string $whom)

    {

    echo "Hello " . ($whom ?? "World");

    }
    hello();
    N U L L A B L E TY P E S

    View full-size slide

  220. N U L L A B L E TY P E S
    function hello(?string $whom)

    {

    echo "Hello " . ($whom ?? "World");

    }
    hello();
    Fatal error: Uncaught Error: Too few arguments
    to function hello(), 0 passed in on line
    6 and exactly 1 expected in :2

    View full-size slide

  221. N U L L A B L E TY P E S
    function hello(?string $whom)

    {

    echo "Hello " . ($whom ?? "World");

    }
    hello();

    View full-size slide

  222. N U L L A B L E TY P E S
    function hello(?string $whom)

    {

    echo "Hello " . ($whom ?? "World");

    }
    hello(null);

    View full-size slide

  223. N U L L A B L E TY P E S
    function hello(?string $whom)

    {

    echo "Hello " . ($whom ?? "World");

    }
    hello(null);

    View full-size slide

  224. N U L L A B L E TY P E S
    function hello(?string $whom

    {

    echo "Hello " . ($whom ?? "World");

    }
    hello(
    )
    );
    null

    View full-size slide

  225. N U L L A B L E TY P E S
    function hello(?string $whom

    {

    echo "Hello " . ($whom ?? "World");

    }
    hello(
    = null)
    );

    View full-size slide

  226. N U L L A B L E R E T U R N TY P E S

    View full-size slide

  227. N U L L A B L E TY P E S
    function hello(?string $whom): string

    {
    if ($whom !== null) {

    return "Hello $whom";
    }
    }
    echo hello("World"); // Hello World

    View full-size slide

  228. N U L L A B L E TY P E S
    function hello(?string $whom): string

    {
    if ($whom !== null) {

    return "Hello $whom";
    }
    }
    echo hello("World"); // Hello World

    View full-size slide

  229. function hello(?string $whom): string

    {
    if ($whom !== null) {

    return "Hello $whom";
    }
    }
    echo hello("World"); // Hello World
    N U L L A B L E TY P E S

    View full-size slide

  230. function hello(?string $whom): string

    {
    if ($whom !== null) {

    return "Hello $whom";
    }
    }
    echo hello("World"); // Hello World
    N U L L A B L E TY P E S

    View full-size slide

  231. N U L L A B L E TY P E S
    function hello(?string $whom): string

    {
    if ($whom !== null) {

    return "Hello $whom";
    }
    }
    echo hello(null);

    View full-size slide

  232. N U L L A B L E TY P E S
    TypeError: Return value of hello() must be of
    the type string, none returned

    View full-size slide

  233. N U L L A B L E TY P E S
    function hello(?string $whom): string

    {
    if ($whom !== null) {

    return "Hello $whom";
    }
    }
    echo hello(null);

    View full-size slide

  234. N U L L A B L E TY P E S
    function hello(?string $whom): ?string

    {
    if ($whom !== null) {

    return "Hello $whom";
    }
    }
    echo hello(null);

    View full-size slide

  235. N U L L A B L E TY P E S
    TypeError: Return value of hello() must be of
    the type string, none returned

    View full-size slide

  236. N U L L A B L E TY P E S
    function hello(?string $whom): ?string

    {
    if ($whom !== null) {

    return "Hello $whom";
    }

    return;
    }
    echo hello(null);

    View full-size slide

  237. N U L L A B L E TY P E S
    Fatal error: A function with return type must
    return a value (did you mean "return null;"
    instead of "return;"?)

    View full-size slide

  238. N U L L A B L E TY P E S
    function hello(?string $whom): ?string

    {
    if ($whom !== null) {

    return "Hello $whom";
    }

    return
    }
    echo hello(null);
    ;

    View full-size slide

  239. N U L L A B L E TY P E S
    function hello(?string $whom): ?string

    {
    if ($whom !== null) {

    return "Hello $whom";
    }

    return
    }
    echo hello(null);
    null;

    View full-size slide

  240. N U L L A B L E TY P E S
    function hello(?string $whom): ?string

    {
    if ($whom !== null) {

    return "Hello $whom";
    }

    return
    }
    echo hello(null);
    null;
    // null

    View full-size slide

  241. CU R R E N T: P H P 7 . 1 . 0 B E TA 3

    View full-size slide

  242. G O T E ST !

    View full-size slide

  243. B E YO N D P H P 7 . 1

    View full-size slide

  244. CU R R E N T LY 2 6 R FCS
    ( A N D O N E F O R P H P 8 . 0 ! )

    View full-size slide

  245. W E W A N T YO U !
    Credit: NASA

    View full-size slide

  246. 6 0 % + M A R K E T S H A R E

    View full-size slide

  247. H U G E P E R FO R M A N C E W I N S

    View full-size slide

  248. M U LT I P L E X I N G
    CC-BY: vadikunc

    View full-size slide

  249. S E R V E R P US H
    CC-BY: Steven Depolo

    View full-size slide

  250. N E W A R C H I T E CT U R E & T E C H N I Q U E S

    View full-size slide

  251. A SY N C H R O N O US / PA R A L L E L

    View full-size slide

  252. W E A R E A CO M M U N I TY

    View full-size slide

  253. I N S U M M A R Y

    View full-size slide

  254. M I D - N O V E M B E R 2 0 1 6

    View full-size slide

  255. T H E F U T U R E I S A W E S O M E !
    CC-BY-SA: Steven Gerner

    View full-size slide

  256. M AY B E Y O U ?
    R E L E A S E M A N A G E R

    View full-size slide

  257. T H A N K YO U !
    Twitter:
    Email:
    Slides:
    @dshafik
    [email protected]
    http://daveyshafik.com/slides

    View full-size slide