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

Essential PHP 7 | PHP[World]

Essential PHP 7 | PHP[World]

Presented on November 16 2016 at PHP[World], Washington DC, United States.
https://world.phparch.com/
---------------------------------------------------------------
Overview of the most important changes introduced with PHP 7. We’ve all heard that PHP 7 is fabulous: faster than any previous PHP version and even HHVM, plus some nifty new functionality and much better exception management. But what do we need to do to make our code compatible with PHP 7? What will break and how do we avoid this?

Juliette Reinders Folmer

November 16, 2016
Tweet

More Decks by Juliette Reinders Folmer

Other Decks in Programming

Transcript

  1. What Can You Expect ? New features! Less BC breaks

    than upgrading to 5.4! PHPNG (PHP Next-Gen) Speed !
  2. So Long And Thanks For All The Fish MySql &

    MsSql extensions Ereg Posix Regex PHP 5.5 and lower
  3. • dl() on fpm-fcgi • set_magic_quotes_runtime() • set_socket_blocking() • mcrypt_generic_end()

    • mcrypt_ecb() • mcrypt_cnc() • mcrypt_cfb() • datefmt_set_timezone_id • IntlDateFormatter::setTimeZoneID • call_user_method() • call_user_method_array() Removed Functions
  4. • xsl.security_prefs • Input encoding: – iconv.input_encoding – Iconv.internal_encoding –

    mbstring.http_input – mbstring.http_output – mbstring.internal_encoding Removed ini Options
  5. What Will Break ? Numeric Hex strings Alternative PHP tags

    <?php echo '0xCC00F9' + 42; echo is_numeric('0xCC00F9'); // PHP 5: 13369635 / true // PHP 7: 42 / false
  6. What Will Break ? Multiple default: Division by zero Numeric

    Hex strings Alternative PHP tags <?php switch ( $variable ) { default: echo 'default'; break; case 'a': echo 'a'; break; default: echo $variable; break; }
  7. What Will Break ? Static vs $this <?php class MyClass

    { public $property = 'hello!'; public function example() { echo $this->property; } } MyClass::example();
  8. What Will Break ? preg_replace /e Static vs $this new

    ... by reference Some Variable Variables <?php $a =& new stdClass;
  9. Uniform Variable Syntax Syntax Old Interpretation New Interpretation $$var[‘key1’][‘key2’] ${$var[‘key1’][‘key2’]}

    ($$var)[‘key1’][‘key2’] $var->$prop[‘key’] $var->{$prop[‘key’]} ($var->$prop)[‘key’] $var->$prop[‘key’]() $var->{$prop[‘key’]}() ($var->$prop)[‘key’]() Class::$var[‘key’]() Class::{$var[‘key’]}() (Class::$var)[‘key’]()
  10. What Will Break ? $HTTP_ RAW_ POST_ DATA Invalid octal

    literals list() vs string access Redefining function args
  11. PHP4 Constructors <?php class MyClass { function __construct() { //

    Constructor actions. } function MyClass() { self::construct(); } } class MyGrandChild extends ParentClass { function __construct() { MyClass::MyClass(); } }
  12. What Will Break ? func_get_ args() PHP4 construc- tors <?php

    function example( $string ) { $string = 'oops'; $args = func_get_args(); echo $args[0]; } example( 'test' ); // PHP 5: 'test' // PHP 7: 'oops'
  13. What Will Break ? func_get_ args() Reserved words PHP4 construc-

    tors Internal array pointer vs foreach() <?php $array = array(0, 1, 2); foreach ($array as &$val) { var_dump(current($array)); } // PHP 5: 1, 2, false // PHP 7: 0, 0, 0
  14. PHP5.3+ on Steriods Bind Closure on Call Group Use Declarations

    Anonymous Classes Generator Enhancements Assertions
  15. Goodies! Spaceship Unicode Escapes Strict Typing More Exception Types More

    Catchable Errors Uniform Variable Syntax Null Coalesce Scalar Type Hints & Return Type Hints
  16. More Goodies! Session options Preg_ replace_ callback_ array() intdiv() Expectations

    Closure call() Filtered unserialize() Exceptions on Fatals IntlChar Class
  17. PHP 7.1 Goodies! List with keys Multi catch iterable type

    hint Symmetric array destructuring void return type Nullable types Negative string offset support Class constant visibility
  18. • PHP 7 Compatibility Checker – https://github.com/sstalle/php7cc • PHP Compatibility

    Code Standard – https://github.com/wimg/PHPCompatibility/ • PHP CompatInfo – http://php5.laurent-laville.org/compatinfo/ Check Your Application
  19. • Are the PHP Extensions Ready ? – https://github.com/gophp7/gophp7-ext/wiki/extensions- catalog

    • Need a Dev Box ? – https://github.com/rlerdorf/php7dev • PHP 7 to PHP 5.6 transphiler – https://github.com/jaytaph/Transphpile • PHP Cheatsheets – http://phpcheatsheets.com/ Useful
  20. Slides will be posted to http://speakerdeck.com/jrf Please give feedback at

    https://joind.in/talk/aedbe Thank you ! Essential PHP 7