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

Introduction to PHP 7

Introduction to PHP 7

A short presentation highlighting the new and removed features of PHP 7

Paul McBride

February 05, 2016
Tweet

More Decks by Paul McBride

Other Decks in Technology

Transcript

  1. OVERVIEW ̣ History of PHP ̣ Whats new in PHP

    7 ̣ Removed and deprecated features ̣ References ̣ Questions
  2. History of PHP Jun 1995 Released by Rasmus Lerdorf Jun

    1998 PHP 3 Released May 2000 PHP 4 Released
  3. Dec 2015 PHP 7 Released Mar 2010 PHP 6 is

    abandoned Feb 2016 Paul gives a great talk on PHP 7
  4. SCALAR TYPE DECLARATIONS <?php
 
 function greeting(string $name)
 {
 return

    "Hello, {$name}";
 } ̣ String ̣ Integer ̣ Float ̣ Boolean New types
  5. NULL COALESCING OPERATOR <?php
 
 // Pre PHP 7
 $username

    = isset($_GET['user']) ? $_GET['user'] : 'nobody'; <?php $username = $_GET['user'] ?? 'nobody'; <?php $username = $_GET['user'] ?? $_POST['user'] ?? 'nobody';
  6. SPACESHIP OPERATOR <?php
 
 // Integers
 echo 1 <=> 1;

    // 0
 echo 1 <=> 2; // -1
 echo 2 <=> 1; // 1
 
 // Floats
 echo 1.5 <=> 1.5; // 0
 echo 1.5 <=> 2.5; // -1
 echo 2.5 <=> 1.5; // 1
 
 // Strings
 echo "a" <=> "a"; // 0
 echo "a" <=> "b"; // -1
 echo "b" <=> "a"; // 1
  7. CONSTANT ARRAYS <?php
 
 define('ANIMALS', [
 'dog',
 'cat',
 'bird'
 ]);


    
 echo ANIMALS[1]; // outputs "cat" Arrays can now now be defined using define()
  8. GROUP USE DECLARATIONS <?php
 
 // Pre PHP 7 code


    use some\namespace\ClassA;
 use some\namespace\ClassB;
 use some\namespace\ClassC as C; <?php
 
 // PHP 7+ code
 use some\namespace\{ClassA, ClassB, ClassC as C};
  9. OTHER FEATURES ̣ Better unicode support ̣ Integer division with

    intdiv() ̣ Improved error handling ̣ Session_start() can now take an options array ̣ unserialize() filter ̣ CSPRNG Functions
  10. REMOVED FEATURES ereg_* ̣ ASP-style tags ̣ PHP script tags

    ̣ All functions ̣ The mysql extension (and the functions) <% <%= %> <script language=”php”> mysql_*
  11. DEPRECATED FEATURES ̣ PHP 4 style constructors ̣ Static calls

    to non-static methods ̣ Salt option for password_hash()