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

Essential PHP7

Essential PHP7

Overview of the most important changes coming with PHP 7.
We’ve all heard that PHP 7 is fabulous: faster than any previous PHP version and even HHVM, but what do we need to do to make our code compatible with PHP 7 ?

2776198ea9584b6c0d4b494293b8d635?s=128

Juliette Reinders Folmer

September 26, 2015
Tweet

Transcript

  1. Juliette Reinders Folmer @jrf_nl WordCamp Netherlands 2015 Essential PHP 7

  2. Who Am I? Independent Consultant Contributor to LimeSurvey, WordPress and

    more Plugin author & contributor to many more
  3. None
  4. What Happened to PHP 6 ? • Unicode – ICU

    • Publications
  5. None
  6. None
  7. How Fast ?!?!? Benchmarks courtesy of Zend Technologies

  8. How Fast ?!?!? Benchmarks courtesy of Rasmus Lerdorf

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

    than upgrading to 5.4! PHPNG (PHP Next-Gen) Speed !
  10. When ? 12 November 2015 Currently on RC3

  11. What will change ?

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

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

    mbstring.http_input – mbstring.http_output – mbstring.internal_encoding Removed ini Options
  15. 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
  16. But WordPress.....

  17. Being Forward Compatible can be as Important as Being Backwards

    Compatible
  18. 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
  19. In 2025..... (or thereabouts)

  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’;
  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_replac e_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 Useful
  33. Slides will be posted to http://speakerdeck.com/jrf Thank you ! Essential

    PHP 7