SlideShare a Scribd company logo
1 of 17
Download to read offline
What’s new in PHP 7.1
And why you really shouldn’t be using PHP5 anymore…
PHP Cambridge, 12th December 2016
Simon Jones, Studio 24
PHP 7.1
• Released 1st Dec 2017
• PHP 5.6 end of life 31 Dec 2018
• PHP 5.4 and 5.5 no longer supported
• WordPress now recommends PHP 7 

(though still works on PHP 5.2

which was released over.. Nine. Years. Ago!)
Supported versions of PHP
http://php.net/supported-versions.php
Why PHP 7?
• Current, stable & supported version of PHP
• Stricter, more secure, and faster!
• Twice as fast for most applications
• Reduced memory usage
http://talks.php.net/fluent15#/wpbench
New features
PHP 5.5
password_hash()

Generators

Zend Optimiser+ opcode cache (OPcache)
PHP 5.6
Constant expressions
Variadic functions (...$params)
PHP 7.0
Scalar type, return type declarations
Exception hierarchy
Spaceship operator <=>
PHP 7.1
Class constant visibility

Nullable types, void return type, iterable pseudo-type
Multi catch exception handling
• Removed from PHP..
• mysql_* functions (use PDO)
• mssql_* functions (use PDO)
• ereg_* functions (use preg_*)
• ASP & script style tags 

<% %> 

<script language=“php”> </script>
• foreach no longer changes the internal array pointer
What breaks / changes in PHP 7.0?
• Error exception thrown when invoking user-defined
functions with too few arguments



function hello($name, $age) { }

echo hello("Simon");
• DateTime constructor includes microseconds, 

be careful when comparing:



new DateTime() == new DateTime();
What breaks / changes in PHP 7.1?
Going, going…
• PHP 4 style constructors



class MyClass {

function MyClass() {}

}
• Static calls to non-static methods



class MyClass {

public function print() {}

}

MyClass::print();
Two new features

Error exceptions & type hinting
• Fatal errors throw exceptions. Yay!
• Custom error handlers may no longer work
Changes to error handling
http://php.net/manual/en/language.errors.php7.php
Type hinting
Scalar type hinting

function hello (string $name, int $age) {

echo "Hello $name, you are nearly " . $age + 1;

}
Return types

function hello (string $name, int $age) : string {

return "Hello $name, you are nearly " . $age + 1;

}
Strict typing
By default, PHP will coerce values of the wrong type into
the expected scalar type if possible. 

function hello (string $name, int $age) { 

echo "Hello $name, you are nearly " . $age + 1;

}

This is OK

hello("Simon", "42");
Strict typing
Unless you enable strict mode

declare(strict_types=1);

function hello (string $name, int $age) { 

echo "Hello $name, you are nearly " . $age + 1;

}
This throws a Fatal error exception

hello("Simon", "42");
Type hinting..
PHP 5.0
Class Name

self
PHP 5.1 array
PHP 5.4 callable
PHP 7.0
bool
float
int
string
PHP 7.1
iterable (array or Traversable)

Nullable types, e.g. ?string
void return type
Migration
• Upgrade to PHP5.6
• Then PHP7
• Migration guides:

http://php.net/manual/en/migration56.php

http://php.net/manual/en/migration70.php

http://php.net/manual/en/migration71.php
Thanks!

More Related Content

What's hot

BDD style Unit Testing
BDD style Unit TestingBDD style Unit Testing
BDD style Unit Testing
Wen-Tien Chang
 
Php(report)
Php(report)Php(report)
Php(report)
Yhannah
 
Coldfusion
ColdfusionColdfusion
Coldfusion
Ram
 

What's hot (17)

Loops PHP 04
Loops PHP 04Loops PHP 04
Loops PHP 04
 
Introduction to php php++
Introduction to php php++Introduction to php php++
Introduction to php php++
 
Php introduction and configuration
Php introduction and configurationPhp introduction and configuration
Php introduction and configuration
 
PHP
PHPPHP
PHP
 
Php mysql
Php mysqlPhp mysql
Php mysql
 
Php Tutorial
Php TutorialPhp Tutorial
Php Tutorial
 
BDD style Unit Testing
BDD style Unit TestingBDD style Unit Testing
BDD style Unit Testing
 
Introduction to php
Introduction to phpIntroduction to php
Introduction to php
 
Php
PhpPhp
Php
 
Chapter 02 php basic syntax
Chapter 02   php basic syntaxChapter 02   php basic syntax
Chapter 02 php basic syntax
 
Wt unit 5
Wt unit 5Wt unit 5
Wt unit 5
 
Automating Your Daily Tasks with Scripting - RubyConf 2015 Taiwan
Automating Your Daily Tasks with Scripting - RubyConf 2015 TaiwanAutomating Your Daily Tasks with Scripting - RubyConf 2015 Taiwan
Automating Your Daily Tasks with Scripting - RubyConf 2015 Taiwan
 
Ruby Basics
Ruby BasicsRuby Basics
Ruby Basics
 
RubyMotion #jbday
RubyMotion #jbdayRubyMotion #jbday
RubyMotion #jbday
 
Php(report)
Php(report)Php(report)
Php(report)
 
10 Groovy Little JavaScript Tips
10 Groovy Little JavaScript Tips10 Groovy Little JavaScript Tips
10 Groovy Little JavaScript Tips
 
Coldfusion
ColdfusionColdfusion
Coldfusion
 

Viewers also liked

Execute MySQL query using command prompt
Execute MySQL query using command promptExecute MySQL query using command prompt
Execute MySQL query using command prompt
Ikhwan Krisnadi
 
Form Processing In Php
Form Processing In PhpForm Processing In Php
Form Processing In Php
Harit Kothari
 
State management
State managementState management
State management
Iblesoft
 

Viewers also liked (20)

OOPS Characteristics (With Examples in PHP)
OOPS Characteristics (With Examples in PHP)OOPS Characteristics (With Examples in PHP)
OOPS Characteristics (With Examples in PHP)
 
PHP variables
PHP  variablesPHP  variables
PHP variables
 
Speed up your site with Varnish
Speed up your site with VarnishSpeed up your site with Varnish
Speed up your site with Varnish
 
What we look for 
in people when recruiting
What we look for 
in people when recruitingWhat we look for 
in people when recruiting
What we look for 
in people when recruiting
 
Modern PHP
Modern PHPModern PHP
Modern PHP
 
PHP Presentation
PHP PresentationPHP Presentation
PHP Presentation
 
Font
FontFont
Font
 
Php variables (english)
Php variables (english)Php variables (english)
Php variables (english)
 
Control Structures In Php 2
Control Structures In Php 2Control Structures In Php 2
Control Structures In Php 2
 
Htmltag.ppt
Htmltag.pptHtmltag.ppt
Htmltag.ppt
 
Php ppt
Php pptPhp ppt
Php ppt
 
Arrays in PHP
Arrays in PHPArrays in PHP
Arrays in PHP
 
Execute MySQL query using command prompt
Execute MySQL query using command promptExecute MySQL query using command prompt
Execute MySQL query using command prompt
 
Form Processing In Php
Form Processing In PhpForm Processing In Php
Form Processing In Php
 
State management
State managementState management
State management
 
Execute sql query or sql command sql server using command prompt
Execute sql query or sql command sql server using command promptExecute sql query or sql command sql server using command prompt
Execute sql query or sql command sql server using command prompt
 
Php forms
Php formsPhp forms
Php forms
 
Php tutorial
Php tutorialPhp tutorial
Php tutorial
 
Regular Expressions in PHP
Regular Expressions in PHPRegular Expressions in PHP
Regular Expressions in PHP
 
PHP Summer Training Presentation
PHP Summer Training PresentationPHP Summer Training Presentation
PHP Summer Training Presentation
 

Similar to What's new in PHP 7.1

Upstate CSCI 450 PHP Chapters 5, 12, 13
Upstate CSCI 450 PHP Chapters 5, 12, 13Upstate CSCI 450 PHP Chapters 5, 12, 13
Upstate CSCI 450 PHP Chapters 5, 12, 13
DanWooster1
 

Similar to What's new in PHP 7.1 (20)

TAKING PHP SERIOUSLY - Keith Adams
TAKING PHP SERIOUSLY - Keith AdamsTAKING PHP SERIOUSLY - Keith Adams
TAKING PHP SERIOUSLY - Keith Adams
 
What To Expect From PHP7
What To Expect From PHP7What To Expect From PHP7
What To Expect From PHP7
 
Basics PHP
Basics PHPBasics PHP
Basics PHP
 
Preparing code for Php 7 workshop
Preparing code for Php 7 workshopPreparing code for Php 7 workshop
Preparing code for Php 7 workshop
 
Php7 傳說中的第七隻大象
Php7 傳說中的第七隻大象Php7 傳說中的第七隻大象
Php7 傳說中的第七隻大象
 
Peek at PHP 7
Peek at PHP 7Peek at PHP 7
Peek at PHP 7
 
Php7 HHVM and co
Php7 HHVM and coPhp7 HHVM and co
Php7 HHVM and co
 
Migrating to PHP 7
Migrating to PHP 7Migrating to PHP 7
Migrating to PHP 7
 
Upstate CSCI 450 PHP Chapters 5, 12, 13
Upstate CSCI 450 PHP Chapters 5, 12, 13Upstate CSCI 450 PHP Chapters 5, 12, 13
Upstate CSCI 450 PHP Chapters 5, 12, 13
 
Start using PHP 7
Start using PHP 7Start using PHP 7
Start using PHP 7
 
Php7 hhvm and co
Php7 hhvm and coPhp7 hhvm and co
Php7 hhvm and co
 
The why and how of moving to php 7
The why and how of moving to php 7The why and how of moving to php 7
The why and how of moving to php 7
 
The why and how of moving to php 5.4
The why and how of moving to php 5.4The why and how of moving to php 5.4
The why and how of moving to php 5.4
 
01 basics
01 basics01 basics
01 basics
 
php basic
php basicphp basic
php basic
 
WT_PHP_PART1.pdf
WT_PHP_PART1.pdfWT_PHP_PART1.pdf
WT_PHP_PART1.pdf
 
PHP - Introduction to PHP Fundamentals
PHP -  Introduction to PHP FundamentalsPHP -  Introduction to PHP Fundamentals
PHP - Introduction to PHP Fundamentals
 
Prersentation
PrersentationPrersentation
Prersentation
 
50 shades of PHP
50 shades of PHP50 shades of PHP
50 shades of PHP
 
Php tutorial
Php tutorialPhp tutorial
Php tutorial
 

Recently uploaded

Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Victor Rentea
 
Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire business
panagenda
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Safe Software
 
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Victor Rentea
 

Recently uploaded (20)

Understanding the FAA Part 107 License ..
Understanding the FAA Part 107 License ..Understanding the FAA Part 107 License ..
Understanding the FAA Part 107 License ..
 
MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024
 
presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century education
 
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
 
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
 
Exploring Multimodal Embeddings with Milvus
Exploring Multimodal Embeddings with MilvusExploring Multimodal Embeddings with Milvus
Exploring Multimodal Embeddings with Milvus
 
Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire business
 
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ..."I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...
 
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin WoodPolkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
 
AI in Action: Real World Use Cases by Anitaraj
AI in Action: Real World Use Cases by AnitarajAI in Action: Real World Use Cases by Anitaraj
AI in Action: Real World Use Cases by Anitaraj
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
 
Vector Search -An Introduction in Oracle Database 23ai.pptx
Vector Search -An Introduction in Oracle Database 23ai.pptxVector Search -An Introduction in Oracle Database 23ai.pptx
Vector Search -An Introduction in Oracle Database 23ai.pptx
 
JohnPollard-hybrid-app-RailsConf2024.pptx
JohnPollard-hybrid-app-RailsConf2024.pptxJohnPollard-hybrid-app-RailsConf2024.pptx
JohnPollard-hybrid-app-RailsConf2024.pptx
 
AWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of Terraform
 
Artificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyArtificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : Uncertainty
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
 
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
 
CNIC Information System with Pakdata Cf In Pakistan
CNIC Information System with Pakdata Cf In PakistanCNIC Information System with Pakdata Cf In Pakistan
CNIC Information System with Pakdata Cf In Pakistan
 
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
 
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
 

What's new in PHP 7.1

  • 1. What’s new in PHP 7.1 And why you really shouldn’t be using PHP5 anymore… PHP Cambridge, 12th December 2016 Simon Jones, Studio 24
  • 2. PHP 7.1 • Released 1st Dec 2017 • PHP 5.6 end of life 31 Dec 2018 • PHP 5.4 and 5.5 no longer supported • WordPress now recommends PHP 7 
 (though still works on PHP 5.2
 which was released over.. Nine. Years. Ago!)
  • 3. Supported versions of PHP http://php.net/supported-versions.php
  • 4. Why PHP 7? • Current, stable & supported version of PHP • Stricter, more secure, and faster! • Twice as fast for most applications • Reduced memory usage
  • 6. New features PHP 5.5 password_hash()
 Generators
 Zend Optimiser+ opcode cache (OPcache) PHP 5.6 Constant expressions Variadic functions (...$params) PHP 7.0 Scalar type, return type declarations Exception hierarchy Spaceship operator <=> PHP 7.1 Class constant visibility
 Nullable types, void return type, iterable pseudo-type Multi catch exception handling
  • 7. • Removed from PHP.. • mysql_* functions (use PDO) • mssql_* functions (use PDO) • ereg_* functions (use preg_*) • ASP & script style tags 
 <% %> 
 <script language=“php”> </script> • foreach no longer changes the internal array pointer What breaks / changes in PHP 7.0?
  • 8. • Error exception thrown when invoking user-defined functions with too few arguments
 
 function hello($name, $age) { }
 echo hello("Simon"); • DateTime constructor includes microseconds, 
 be careful when comparing:
 
 new DateTime() == new DateTime(); What breaks / changes in PHP 7.1?
  • 9. Going, going… • PHP 4 style constructors
 
 class MyClass {
 function MyClass() {}
 } • Static calls to non-static methods
 
 class MyClass {
 public function print() {}
 }
 MyClass::print();
  • 10. Two new features
 Error exceptions & type hinting
  • 11. • Fatal errors throw exceptions. Yay! • Custom error handlers may no longer work Changes to error handling http://php.net/manual/en/language.errors.php7.php
  • 12. Type hinting Scalar type hinting
 function hello (string $name, int $age) {
 echo "Hello $name, you are nearly " . $age + 1;
 } Return types
 function hello (string $name, int $age) : string {
 return "Hello $name, you are nearly " . $age + 1;
 }
  • 13. Strict typing By default, PHP will coerce values of the wrong type into the expected scalar type if possible. 
 function hello (string $name, int $age) { 
 echo "Hello $name, you are nearly " . $age + 1;
 }
 This is OK
 hello("Simon", "42");
  • 14. Strict typing Unless you enable strict mode
 declare(strict_types=1);
 function hello (string $name, int $age) { 
 echo "Hello $name, you are nearly " . $age + 1;
 } This throws a Fatal error exception
 hello("Simon", "42");
  • 15. Type hinting.. PHP 5.0 Class Name
 self PHP 5.1 array PHP 5.4 callable PHP 7.0 bool float int string PHP 7.1 iterable (array or Traversable)
 Nullable types, e.g. ?string void return type
  • 16. Migration • Upgrade to PHP5.6 • Then PHP7 • Migration guides:
 http://php.net/manual/en/migration56.php
 http://php.net/manual/en/migration70.php
 http://php.net/manual/en/migration71.php