Pro Yearly is on sale from $80 to $50! »

Essential PHP 7

Essential PHP 7

Presented on May 18th 2016 at NijmegenPHP, Nijmegen, The Netherlands.
http://www.meetup.com/NijmegenPHP/
---------------------------------------------------------------
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, 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?

Transcript

  1. Juliette Reinders Folmer @jrf_nl NijmegenPHP May 2016 Essential PHP 7

  2. Who Am I? Self-employed, Independent Consultant Creator PHPCheatsheets phpcheatsheets.com Avid

    open source contributor
  3. None
  4. What Happened to PHP 6 ? • Unicode – ICU

    • Publications
  5. None
  6. None
  7. How Fast ?!?!?

  8. How Fast ?!?!?

  9. How Fast ?!?!?

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

    than upgrading to 5.4! PHPNG (PHP Next-Gen) Speed !
  11. Version Support

  12. What has changed ?

  13. So Long And Thanks For All The Fish MySql extension

    Ereg Posix Regex PHP 5.4 and lower
  14. • 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
  15. • xsl.security_prefs • Input encoding: – iconv.input_encoding – Iconv.internal_encoding –

    mbstring.http_input – mbstring.http_output – mbstring.internal_encoding Removed ini Options
  16. What Will Break ? preg_replace /e Static vs $this new

    ... by reference Multiple default: Division by zero Numeric Hex strings Some Variable Variables Alternative PHP tags
  17. What Will Break ? func_get_ args() Reserved words PHP4 construc-

    tors $HTTP_ RAW_ POST_ DATA Invalid octal literals list() vs string access Internal array pointer vs foreach() Redefining function args
  18. Being Forward Compatible can be as Important as Being Backwards

    Compatible
  19. Cross-version bootstrap.php version_compare() function_exists() class_exists() method_exists() defined()  class-php53-code.php 

    class-php70-code.php  class-php-compat.php
  20. Goodies! Spaceship Unicode Escapes Strict Typing More Exception Types More

    Catchable Errors Uniform Variable Syntax Null Coalesce Scalar Type Hints & Return Type Hints
  21. 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’]()
  22. None
  23. Combined Comparison Operator <?php // Pre PHP 7 function sort_order(

    $a, $b ) { return ( $a < $b ) ? -1 : ( ( $a > $b ) ? 1 : 0 ); } // PHP7+ function sort_order( $a, $b ) { return $a <=> $b; }
  24. Unicode Codepoint Escape Syntax <?php echo “\u{1F47D} \u{260E} \u{1F3E1}”; ☎

  25. Null Coalesce Operator // Pre PHP 7 $post = (

    ( isset( $post ) ? $post : ‘default’ ); // PHP7+ $post = $post ?? ‘default’; // PHP 7.1+ $post ??= ‘default’;
  26. Scalar Type Hints

  27. Scalar Type Hints & Strict Typing <?php declare( strict_types =

    1 ); // must be first line function get_post_type( int $post_id ) { // do something; return $post_type; } try { get_post_type( $post_object ); } catch ( \TypeException $e ) { var_dump( $e ); }
  28. Return Type Hints <?php function is_post( int $post_id ) :

    bool { // do something return ( ‘post’ === $post->post_type ); }
  29. More Goodies! Session options Preg_ replace_ callback_ array() intdiv() Expectations

    Closure call() Filtered unserialize() Exceptions on Fatals IntlChar Class
  30. PHP5.3+ on Steriods Bind Closure on Call Group Use Declarations

    Anonymous Classes Generator Enhancements Assertions
  31. None
  32. • Are the PHP Extensions Ready ? – http://gophp7.org/ –

    https://github.com/gophp7/gophp7-ext/wiki/extensions- catalog • PHP 7 Compatibility Checker – https://github.com/sstalle/php7cc • PHP Compatibility – https://github.com/wimg/PHPCompatibility/ • Need a Dev Box ? – https://github.com/rlerdorf/php7dev • PHP 7 to PHP 5.6 transphiler – https://github.com/jaytaph/Transphpile Useful
  33. Slides will be posted to http://speakerdeck.com/jrf Thank you ! Essential

    PHP 7