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

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 ?

Juliette Reinders Folmer

September 26, 2015
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 extension

    Ereg Posix Regex PHP 5.4 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 ? preg_replace /e Static vs $this new

    ... by reference Multiple default: Division by zero Numeric Hex strings Some Variable Variables Alternative PHP tags
  6. Goodies! Spaceship Unicode Escapes Strict Typing More Exception Types More

    Catchable Errors Uniform Variable Syntax Null Coalesce Scalar Type Hints & Return Type Hints
  7. 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’]()
  8. 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; }
  9. Null Coalesce Operator // Pre PHP 7 $post = (

    ( isset( $post ) ? $post : ‘default’ ); // PHP7+ $post = $post ?? ‘default’;
  10. 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 ); }
  11. Return Type Hints <?php function is_post( int $post_id ) :

    bool { // do something return ( ‘post’ === $post->post_type ); }
  12. More Goodies! Session options Preg_replac e_callback_ array() intdiv() Expectations Closure

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

    Anonymous Classes Generator Enhancements Assertions
  14. • 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