SlideShare a Scribd company logo
START USING PHP 7.X
Oscar Merida, @omerida
August 1, 2017
HELLO
Slides: http://phpa.me/oam-use-php7
PHP 5.6 IS EOL
PHP 5 released July 2004
php 5.6: security xes through Dec. 31, 2018
Active support for 5.6 ended Jan 19, 2017. It’s worth noting the last signigicant version of PHP 5 was released Aug. 2014,
almost 3 years ago.
If you have an older applicaiton or clients with one, use a proactive approach. Don’t wait until something bad happens and then
blame them for not upgrading.
VULNERABILITIES IN PHP
lists 555 vulnerabilities for PHP.cvedetails.com
This does not mean PHP 7 is vulnerability free or that PHP 5 is riddled with them. It just means the PHP core team is not fixing
vulnerabilities in versions prior to 5.6. After this year, they will only fix PHP 7. You’re distributions may back-port fixes to older
versions, so you may have more time.
PHP 7 USES LESS MEMORY
A signi cant amount of work went into optimizing how the
Zend Engine manages memory.
Packed and Immutable Arrays consume less memory.
Reduced memory allocations for variables.
Smarter reference handling.
The Zend Engine is the name given to the PHP interpreter by Zeev Suraski and Andi Gutman shipped with PHP 4. Packed
arrays are arrays with numeric indexes, in order. Immutable arrays contain values which don’t change like integers, strings,
other immutable arrays.
AS A RESULT, IT USES LESS CPU
Performs fewer memory operations
Optimize how variables in strings are interpolated
The black re.io blog has a series detailing the changes in the
Zend Engine.
PHP 7 IS LESS RESOURCE INTENSIVE
Less memory, CPU means == Need Fewer, less powerful
servers.
As we’ll see, this can be a powerful argument to your boss or CFO in making a case for upgrading.
BENCHMARKS
for PHP 7:Zend benchmarks
Drupal 7: 316 vs 182 req/sec
Drupal 8: 55 vs 32
From by Rasmus LerdorfSpeeding up the Web with PHP 7
Drupal 8: 2,580 reqs/s vs. 1,401
WordPress: 604 vs 270
Zend, the company started by Zeev and Andi, provided an infographic showing the improvements they measured.
Also, Rasmus Lerdorf, the original creator of PHP, has a talk detailing and measuring the performance improvements.
IN PRODUCTION: BADOO
switching to PHP 7 saved $1M.Baddoo.com estimates
Badoo is a social discovery network. Visit this link for real-world data. In summary, they reduced response time by 40%, overall
load on their clusters fell below 50%, and memory usage reduced to 1/8th.
Allows them to save costs by eliminating need for 400 servers, half of their machines.
IN PRODUCTION: DAILY MOTION
We can handle twice more traf c, with the same
infrastructure.
PHP 7 deployment at Dailymotion
Dailymotion is a video sharing cite. They used etsy/phan to identify incompatibilities. According to them, it took less than a week
to migrate their codebase.
NEW LANGUAGE FEATURES
SCALAR TYPE HINTS
function getRecord(int $id) {
// use integer $id to lookup item from DB
}
function concatNames(string $first, string $last) {
return $first . ' ' . $last;
}
PHP 5 had typehints for arrays, callables, classes, and interface. PHP 7 adds it for scalar values. Remove boilerplate code to
check if parameters are valid.
SCALAR TYPE HINT:
Enable strict mode to enforce them.
<?php
declare(strict_types = 1);
// ...
// if $id isn't a string, throws an error
$record = $db->getRecord($id);
php.net: Strict Typing
Emphasize the calling code has to enable it. In strict mode, throws exceptions if types don’t match. Otherwise, the Zend Engine
will convert it automatically for you. As a result, int, bool, string, float are now reserved words. You can’t have classes or
functions with the same name.
COERCING VALUES
If not in strict mode, PHP tries to convert a variable to the
de ned type.
Type declaration int oat string bool object
int yes yes* yes† yes no
oat yes yes yes† yes no
string yes yes yes yes yes‡
bool yes yes yes yes no
RETURN TYPE HINTS
function getRecord(int $id) : PersonRecord {
// use integer $id to lookup item from DB
}
function concatNames(string $first, string $last) : string {
return $first . ' ' . $last;
}
As with type hinting, in strict mode will throw errors. For static types, they’ll be coerced into the correct type. For example,
integers will be turned to strings, etc.
ENGINE EXCEPTIONS
Almost all errors are now catchable exceptions.
It’s now possible to catch almost all errors PHP may encounter and handle them gracefully.
NEW OPERATORS
1. Spaceship operator <=>
$a <=> $b
2. Null coallesce operator ??
$name = $user['name'] ?? 'anonymous';
These operators introduce syntactic sugar to make code you write more concise. The spaceship operator compares two values,
returns -1, 0, 1. Useful for custom sorting functions.
The null coallesce operator assigns a default value if the expected one is not set.
UNIFORM VARIABLE SYNTAX
$field['name' => 'my_field', 'value' => 'target_id'];
$node->$field['value'];
// $node->{$field['value']}; // PHP 5 $node->target_id;
// {$node->$field}['value']; // PHP 7 error, $field is not a string
PHP 7 is consistent when evaluating variables by interpreting them from left to right. If you have some tricky usages of variables
within variables, use curly braces to explicitly set the order.
OTHER CHANGES
PHP 7.1: nullable type and void return types.
function doSomething(?string input): ?string
PHP 7.2: libsodium support
Nullable types and void return allow you to make these optional. No error thrown if they are missing.
Libsodium adds modern cryptography support into core. Aim is to provide high quality crypto functions.
REMOVED FUNCTIONALITY
PHP 7 did remove features marked as deprecated in PHP 5.
Hence the version bump. PHP RFC: Removed deprecated
functionality
Leading up to PHP 7’s release, an RFC lists all the functionality to be removed. These were already things marked as
deprecated in PHP 5.
MYSQL
Old mysql_ family of functions removed
Update code to use PDO and prepared statements
mysqli extension is also an option
This change won’t affect Drupal but if you have custom databases, it’s time to modernize your code.
ALSO REMOVED
ASP and Script tags <% and
<script language="php">
ereg_ regular expressions. Use preg_ functions
magic_quotes functionality
Some iconv.* and mbstring.* php.ini settings
preg_replace() eval modi er
Many more things were removed in PHP 7 to prevent errors, enhance security, or remove seldom-used features.
NEW DEPRECATED
Develop with E_DEPRECATED and E_NOTICES on to see
and x these errors.
Includes:
PHP 4 style constructors.
Static calls to non-static methods.
ext/mcrypt extension.
See Deprecated features in PHP 7.0
Marking some things for removal in PHP 8.
PREPARATION
TEST YOUR SITE
Identify code which needs to be updated.
Ideally, have a test suite to check for failures.
If you don’t already have a test suite, this would be a good time in investing in one (cover critical paths)
READ THE MIGRATION GUIDE
php.net has a guide forMigrating from PHP 5.6.x to PHP 7.0.x
Lists BC changes
Lists Changed and new functions.
Removed Extensions and SAPIs
I’ve given you an overview of the major features and changes in PHP 7.0. This guide is the canonical reference listing all of
them. You should read it before you update your own applicaitons.
DRUPAL CORE
Drupal 8: Core is PHP 7 compatible
Drupal 7: Support PHP 7
Drupal 8 is fully tested and compatible with PHP 7. In fact, Drupal 8 was an important test bed for for candidate releases of PHP
7.
While there are tickets open for D7, ensure you’re using at least 7.50.
DRUPAL MODULES
Update contrib modules to include PHP 7 support.
Webform
Backup & Migrate
As usual, PHP 7 support in contrib is harder to guarantee. Becuase of the efforts to maintain BC, most modules should work
with little or no changes. Many might throw new deprecation notices (php4 style constructors where the class name matches a
function name)
STATIC ANALYZERS
Automatically scan your codebase and nd code which needs
to be upgraded
: tests for PHP7/PHP5 backward compatibility
(and more)
: has compatibility tests too.
: From 5.3+
etsy/phan
exakat
Preparing Legacy Applications for PHP 7 with Phan
monque/PHP-Migration
These tools will automatically inspect your codebase to look for backwards incompatibility breaks. You’ll need to install the php-
ast extenstion for etsy/phan. Exakat depends on gremlin, neo4 packages.
PRE-BUILT ENVIRONMENTS
: PHP 7.1.
Drupal focused, PHP 7.1
for PHP 7.0, 7.1, 7.2
Homestead
DrupalVM
Docker images
Laravel’s Homestead gives you an easy-to-configure LAMP environment. DrupalVM provides a lot, useful if you have many
dependent services like Solr. You can configure it to use PHP 5.6, 7.0, or 7.1. Docker provides official PHP 7 images, more
performant than Vagrant.
DISTROS WITH PHP7
Debian stable has PHP 7.0, use for older releases.
Ubuntu 16.04 LTS has PHP 7.0
Redhat EL: Via Software Collections or 3rd part repos.
Centos 7: from Remi, Webtatic, and
IUS
dotdeb
Precompiled packages
CONCLUSION
PHP 7…
…brings massive performance gains and improvements to the
language to help you write better code. There’s no reason to
stay on PHP 5.
THANK YOU
@omerida
I publish php[architect], a monthly magazine for PHP
developers. Check it out: www.phparch.com
php[world] is our fall conference in Tyson’s Corner.
world.phparch.com

More Related Content

What's hot

Php(report)
Php(report)Php(report)
Php(report)
Yhannah
 
Working Effectively With Legacy Perl Code
Working Effectively With Legacy Perl CodeWorking Effectively With Legacy Perl Code
Working Effectively With Legacy Perl Code
erikmsp
 
Php essentials
Php essentialsPhp essentials
Php essentials
sagaroceanic11
 
php_tizag_tutorial
php_tizag_tutorialphp_tizag_tutorial
php_tizag_tutorial
tutorialsruby
 
Basic of PHP
Basic of PHPBasic of PHP
Basic of PHP
Nisa Soomro
 
Preprocessor in C
Preprocessor in CPreprocessor in C
Preprocessor in C
Prabhu Govind
 
Object Oriented Design Patterns for PHP
Object Oriented Design Patterns for PHPObject Oriented Design Patterns for PHP
Object Oriented Design Patterns for PHP
RobertGonzalez
 
Php tutorial
Php tutorialPhp tutorial
Php tutorial
Mohammed Ilyas
 
Php mysql ppt
Php mysql pptPhp mysql ppt
Preprocessor
PreprocessorPreprocessor
Preprocessor
abhay singh
 
Living With Legacy Code
Living With Legacy CodeLiving With Legacy Code
Living With Legacy Code
Rowan Merewood
 
Pre processor directives in c
Pre processor directives in cPre processor directives in c
Php Tutorial
Php TutorialPhp Tutorial
Php Tutorial
pratik tambekar
 
Introduction to php
Introduction to phpIntroduction to php
Introduction to php
Anjan Banda
 
Dynamic website
Dynamic websiteDynamic website
Dynamic website
salissal
 
Error management
Error managementError management
Error management
daniil3
 
Symfony Components
Symfony ComponentsSymfony Components
Symfony Components
Nuuktal Consulting
 
Preprocessor
PreprocessorPreprocessor
Preprocessor
lalithambiga kamaraj
 
Advanced PHP: Design Patterns - Dennis-Jan Broerse
Advanced PHP: Design Patterns - Dennis-Jan BroerseAdvanced PHP: Design Patterns - Dennis-Jan Broerse
Advanced PHP: Design Patterns - Dennis-Jan Broerse
dpc
 
Php Ppt
Php PptPhp Ppt
Php Ppt
Hema Prasanth
 

What's hot (20)

Php(report)
Php(report)Php(report)
Php(report)
 
Working Effectively With Legacy Perl Code
Working Effectively With Legacy Perl CodeWorking Effectively With Legacy Perl Code
Working Effectively With Legacy Perl Code
 
Php essentials
Php essentialsPhp essentials
Php essentials
 
php_tizag_tutorial
php_tizag_tutorialphp_tizag_tutorial
php_tizag_tutorial
 
Basic of PHP
Basic of PHPBasic of PHP
Basic of PHP
 
Preprocessor in C
Preprocessor in CPreprocessor in C
Preprocessor in C
 
Object Oriented Design Patterns for PHP
Object Oriented Design Patterns for PHPObject Oriented Design Patterns for PHP
Object Oriented Design Patterns for PHP
 
Php tutorial
Php tutorialPhp tutorial
Php tutorial
 
Php mysql ppt
Php mysql pptPhp mysql ppt
Php mysql ppt
 
Preprocessor
PreprocessorPreprocessor
Preprocessor
 
Living With Legacy Code
Living With Legacy CodeLiving With Legacy Code
Living With Legacy Code
 
Pre processor directives in c
Pre processor directives in cPre processor directives in c
Pre processor directives in c
 
Php Tutorial
Php TutorialPhp Tutorial
Php Tutorial
 
Introduction to php
Introduction to phpIntroduction to php
Introduction to php
 
Dynamic website
Dynamic websiteDynamic website
Dynamic website
 
Error management
Error managementError management
Error management
 
Symfony Components
Symfony ComponentsSymfony Components
Symfony Components
 
Preprocessor
PreprocessorPreprocessor
Preprocessor
 
Advanced PHP: Design Patterns - Dennis-Jan Broerse
Advanced PHP: Design Patterns - Dennis-Jan BroerseAdvanced PHP: Design Patterns - Dennis-Jan Broerse
Advanced PHP: Design Patterns - Dennis-Jan Broerse
 
Php Ppt
Php PptPhp Ppt
Php Ppt
 

Similar to Start using PHP 7

Guidelines php 8 gig
Guidelines php 8 gigGuidelines php 8 gig
Guidelines php 8 gig
Ditinus Technology Pvt LTD
 
Winter%200405%20-%20Beginning%20PHP
Winter%200405%20-%20Beginning%20PHPWinter%200405%20-%20Beginning%20PHP
Winter%200405%20-%20Beginning%20PHP
tutorialsruby
 
Winter%200405%20-%20Beginning%20PHP
Winter%200405%20-%20Beginning%20PHPWinter%200405%20-%20Beginning%20PHP
Winter%200405%20-%20Beginning%20PHP
tutorialsruby
 
An overview of upcoming features and improvements of PHP7
An overview of upcoming features and improvements of PHP7An overview of upcoming features and improvements of PHP7
An overview of upcoming features and improvements of PHP7
Cloudways
 
Php7
Php7Php7
Php 7.2 compliance workshop php benelux
Php 7.2 compliance workshop php beneluxPhp 7.2 compliance workshop php benelux
Php 7.2 compliance workshop php benelux
Damien Seguy
 
[4developers2016] PHP 7 (Michał Pipa)
[4developers2016] PHP 7 (Michał Pipa)[4developers2016] PHP 7 (Michał Pipa)
[4developers2016] PHP 7 (Michał Pipa)
PROIDEA
 
Unit 1
Unit 1Unit 1
What To Expect From PHP7
What To Expect From PHP7What To Expect From PHP7
What To Expect From PHP7
Codemotion
 
Introduction into PHP5 (Jeroen van Sluijs)
Introduction into PHP5 (Jeroen van Sluijs)Introduction into PHP5 (Jeroen van Sluijs)
Introduction into PHP5 (Jeroen van Sluijs)
Stefan Koopmanschap
 
Php 5.6 vs Php 7 performance comparison
Php 5.6 vs Php 7 performance comparisonPhp 5.6 vs Php 7 performance comparison
Php 5.6 vs Php 7 performance comparison
Tu Pham
 
Php7 HHVM and co
Php7 HHVM and coPhp7 HHVM and co
Php7 HHVM and co
weltling
 
Php Best Practices
Php Best PracticesPhp Best Practices
Php Best Practices
Ansar Ahmed
 
Php Best Practices
Php Best PracticesPhp Best Practices
Php Best Practices
Ansar Ahmed
 
PHP 7X New Features
PHP 7X New FeaturesPHP 7X New Features
PHP 7X New Features
Thanh Tai
 
Introduction to PHP - Basics of PHP
Introduction to PHP - Basics of PHPIntroduction to PHP - Basics of PHP
Introduction to PHP - Basics of PHP
wahidullah mudaser
 
The why and how of moving to php 8
The why and how of moving to php 8The why and how of moving to php 8
The why and how of moving to php 8
Wim Godden
 
Basics PHP
Basics PHPBasics PHP
Zephir - A Wind of Change for writing PHP extensions
Zephir - A Wind of Change for writing PHP extensionsZephir - A Wind of Change for writing PHP extensions
Zephir - A Wind of Change for writing PHP extensions
Mark Baker
 
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 Start using PHP 7 (20)

Guidelines php 8 gig
Guidelines php 8 gigGuidelines php 8 gig
Guidelines php 8 gig
 
Winter%200405%20-%20Beginning%20PHP
Winter%200405%20-%20Beginning%20PHPWinter%200405%20-%20Beginning%20PHP
Winter%200405%20-%20Beginning%20PHP
 
Winter%200405%20-%20Beginning%20PHP
Winter%200405%20-%20Beginning%20PHPWinter%200405%20-%20Beginning%20PHP
Winter%200405%20-%20Beginning%20PHP
 
An overview of upcoming features and improvements of PHP7
An overview of upcoming features and improvements of PHP7An overview of upcoming features and improvements of PHP7
An overview of upcoming features and improvements of PHP7
 
Php7
Php7Php7
Php7
 
Php 7.2 compliance workshop php benelux
Php 7.2 compliance workshop php beneluxPhp 7.2 compliance workshop php benelux
Php 7.2 compliance workshop php benelux
 
[4developers2016] PHP 7 (Michał Pipa)
[4developers2016] PHP 7 (Michał Pipa)[4developers2016] PHP 7 (Michał Pipa)
[4developers2016] PHP 7 (Michał Pipa)
 
Unit 1
Unit 1Unit 1
Unit 1
 
What To Expect From PHP7
What To Expect From PHP7What To Expect From PHP7
What To Expect From PHP7
 
Introduction into PHP5 (Jeroen van Sluijs)
Introduction into PHP5 (Jeroen van Sluijs)Introduction into PHP5 (Jeroen van Sluijs)
Introduction into PHP5 (Jeroen van Sluijs)
 
Php 5.6 vs Php 7 performance comparison
Php 5.6 vs Php 7 performance comparisonPhp 5.6 vs Php 7 performance comparison
Php 5.6 vs Php 7 performance comparison
 
Php7 HHVM and co
Php7 HHVM and coPhp7 HHVM and co
Php7 HHVM and co
 
Php Best Practices
Php Best PracticesPhp Best Practices
Php Best Practices
 
Php Best Practices
Php Best PracticesPhp Best Practices
Php Best Practices
 
PHP 7X New Features
PHP 7X New FeaturesPHP 7X New Features
PHP 7X New Features
 
Introduction to PHP - Basics of PHP
Introduction to PHP - Basics of PHPIntroduction to PHP - Basics of PHP
Introduction to PHP - Basics of PHP
 
The why and how of moving to php 8
The why and how of moving to php 8The why and how of moving to php 8
The why and how of moving to php 8
 
Basics PHP
Basics PHPBasics PHP
Basics PHP
 
Zephir - A Wind of Change for writing PHP extensions
Zephir - A Wind of Change for writing PHP extensionsZephir - A Wind of Change for writing PHP extensions
Zephir - A Wind of Change for writing PHP extensions
 
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
 

More from Oscar Merida

PHP OOP
PHP OOPPHP OOP
PHP OOP
Oscar Merida
 
Symfony console: build awesome command line scripts with ease
Symfony console: build awesome command line scripts with easeSymfony console: build awesome command line scripts with ease
Symfony console: build awesome command line scripts with ease
Oscar Merida
 
Integration Testing with Behat drupal
Integration Testing with Behat drupalIntegration Testing with Behat drupal
Integration Testing with Behat drupal
Oscar Merida
 
Staying Sane with Drupal NEPHP
Staying Sane with Drupal NEPHPStaying Sane with Drupal NEPHP
Staying Sane with Drupal NEPHP
Oscar Merida
 
Building with Virtual Development Environments
Building with Virtual Development EnvironmentsBuilding with Virtual Development Environments
Building with Virtual Development Environments
Oscar Merida
 
Staying Sane with Drupal (A Develper's Survival Guide)
Staying Sane with Drupal (A Develper's Survival Guide)Staying Sane with Drupal (A Develper's Survival Guide)
Staying Sane with Drupal (A Develper's Survival Guide)
Oscar Merida
 
How to Evaluate your Technical Partner
How to Evaluate your Technical PartnerHow to Evaluate your Technical Partner
How to Evaluate your Technical Partner
Oscar Merida
 
Building with Virtual Development Environments
Building with Virtual Development EnvironmentsBuilding with Virtual Development Environments
Building with Virtual Development Environments
Oscar Merida
 
Publishing alchemy with markdown and pandoc
Publishing alchemy with markdown and pandocPublishing alchemy with markdown and pandoc
Publishing alchemy with markdown and pandoc
Oscar Merida
 
Migrate without migranes
Migrate without migranesMigrate without migranes
Migrate without migranes
Oscar Merida
 
Hitch yourwagon
Hitch yourwagonHitch yourwagon
Hitch yourwagon
Oscar Merida
 

More from Oscar Merida (11)

PHP OOP
PHP OOPPHP OOP
PHP OOP
 
Symfony console: build awesome command line scripts with ease
Symfony console: build awesome command line scripts with easeSymfony console: build awesome command line scripts with ease
Symfony console: build awesome command line scripts with ease
 
Integration Testing with Behat drupal
Integration Testing with Behat drupalIntegration Testing with Behat drupal
Integration Testing with Behat drupal
 
Staying Sane with Drupal NEPHP
Staying Sane with Drupal NEPHPStaying Sane with Drupal NEPHP
Staying Sane with Drupal NEPHP
 
Building with Virtual Development Environments
Building with Virtual Development EnvironmentsBuilding with Virtual Development Environments
Building with Virtual Development Environments
 
Staying Sane with Drupal (A Develper's Survival Guide)
Staying Sane with Drupal (A Develper's Survival Guide)Staying Sane with Drupal (A Develper's Survival Guide)
Staying Sane with Drupal (A Develper's Survival Guide)
 
How to Evaluate your Technical Partner
How to Evaluate your Technical PartnerHow to Evaluate your Technical Partner
How to Evaluate your Technical Partner
 
Building with Virtual Development Environments
Building with Virtual Development EnvironmentsBuilding with Virtual Development Environments
Building with Virtual Development Environments
 
Publishing alchemy with markdown and pandoc
Publishing alchemy with markdown and pandocPublishing alchemy with markdown and pandoc
Publishing alchemy with markdown and pandoc
 
Migrate without migranes
Migrate without migranesMigrate without migranes
Migrate without migranes
 
Hitch yourwagon
Hitch yourwagonHitch yourwagon
Hitch yourwagon
 

Recently uploaded

E-commerce Development Services- Hornet Dynamics
E-commerce Development Services- Hornet DynamicsE-commerce Development Services- Hornet Dynamics
E-commerce Development Services- Hornet Dynamics
Hornet Dynamics
 
Vitthal Shirke Java Microservices Resume.pdf
Vitthal Shirke Java Microservices Resume.pdfVitthal Shirke Java Microservices Resume.pdf
Vitthal Shirke Java Microservices Resume.pdf
Vitthal Shirke
 
OpenMetadata Community Meeting - 5th June 2024
OpenMetadata Community Meeting - 5th June 2024OpenMetadata Community Meeting - 5th June 2024
OpenMetadata Community Meeting - 5th June 2024
OpenMetadata
 
socradar-q1-2024-aviation-industry-report.pdf
socradar-q1-2024-aviation-industry-report.pdfsocradar-q1-2024-aviation-industry-report.pdf
socradar-q1-2024-aviation-industry-report.pdf
SOCRadar
 
GreenCode-A-VSCode-Plugin--Dario-Jurisic
GreenCode-A-VSCode-Plugin--Dario-JurisicGreenCode-A-VSCode-Plugin--Dario-Jurisic
GreenCode-A-VSCode-Plugin--Dario-Jurisic
Green Software Development
 
Mobile App Development Company In Noida | Drona Infotech
Mobile App Development Company In Noida | Drona InfotechMobile App Development Company In Noida | Drona Infotech
Mobile App Development Company In Noida | Drona Infotech
Drona Infotech
 
Energy consumption of Database Management - Florina Jonuzi
Energy consumption of Database Management - Florina JonuziEnergy consumption of Database Management - Florina Jonuzi
Energy consumption of Database Management - Florina Jonuzi
Green Software Development
 
8 Best Automated Android App Testing Tool and Framework in 2024.pdf
8 Best Automated Android App Testing Tool and Framework in 2024.pdf8 Best Automated Android App Testing Tool and Framework in 2024.pdf
8 Best Automated Android App Testing Tool and Framework in 2024.pdf
kalichargn70th171
 
Introducing Crescat - Event Management Software for Venues, Festivals and Eve...
Introducing Crescat - Event Management Software for Venues, Festivals and Eve...Introducing Crescat - Event Management Software for Venues, Festivals and Eve...
Introducing Crescat - Event Management Software for Venues, Festivals and Eve...
Crescat
 
Automated software refactoring with OpenRewrite and Generative AI.pptx.pdf
Automated software refactoring with OpenRewrite and Generative AI.pptx.pdfAutomated software refactoring with OpenRewrite and Generative AI.pptx.pdf
Automated software refactoring with OpenRewrite and Generative AI.pptx.pdf
timtebeek1
 
WWDC 2024 Keynote Review: For CocoaCoders Austin
WWDC 2024 Keynote Review: For CocoaCoders AustinWWDC 2024 Keynote Review: For CocoaCoders Austin
WWDC 2024 Keynote Review: For CocoaCoders Austin
Patrick Weigel
 
A Study of Variable-Role-based Feature Enrichment in Neural Models of Code
A Study of Variable-Role-based Feature Enrichment in Neural Models of CodeA Study of Variable-Role-based Feature Enrichment in Neural Models of Code
A Study of Variable-Role-based Feature Enrichment in Neural Models of Code
Aftab Hussain
 
Lecture 2 - software testing SE 412.pptx
Lecture 2 - software testing SE 412.pptxLecture 2 - software testing SE 412.pptx
Lecture 2 - software testing SE 412.pptx
TaghreedAltamimi
 
Graspan: A Big Data System for Big Code Analysis
Graspan: A Big Data System for Big Code AnalysisGraspan: A Big Data System for Big Code Analysis
Graspan: A Big Data System for Big Code Analysis
Aftab Hussain
 
Measures in SQL (SIGMOD 2024, Santiago, Chile)
Measures in SQL (SIGMOD 2024, Santiago, Chile)Measures in SQL (SIGMOD 2024, Santiago, Chile)
Measures in SQL (SIGMOD 2024, Santiago, Chile)
Julian Hyde
 
Oracle Database 19c New Features for DBAs and Developers.pptx
Oracle Database 19c New Features for DBAs and Developers.pptxOracle Database 19c New Features for DBAs and Developers.pptx
Oracle Database 19c New Features for DBAs and Developers.pptx
Remote DBA Services
 
Neo4j - Product Vision and Knowledge Graphs - GraphSummit Paris
Neo4j - Product Vision and Knowledge Graphs - GraphSummit ParisNeo4j - Product Vision and Knowledge Graphs - GraphSummit Paris
Neo4j - Product Vision and Knowledge Graphs - GraphSummit Paris
Neo4j
 
UI5con 2024 - Keynote: Latest News about UI5 and it’s Ecosystem
UI5con 2024 - Keynote: Latest News about UI5 and it’s EcosystemUI5con 2024 - Keynote: Latest News about UI5 and it’s Ecosystem
UI5con 2024 - Keynote: Latest News about UI5 and it’s Ecosystem
Peter Muessig
 
Oracle 23c New Features For DBAs and Developers.pptx
Oracle 23c New Features For DBAs and Developers.pptxOracle 23c New Features For DBAs and Developers.pptx
Oracle 23c New Features For DBAs and Developers.pptx
Remote DBA Services
 
openEuler Case Study - The Journey to Supply Chain Security
openEuler Case Study - The Journey to Supply Chain SecurityopenEuler Case Study - The Journey to Supply Chain Security
openEuler Case Study - The Journey to Supply Chain Security
Shane Coughlan
 

Recently uploaded (20)

E-commerce Development Services- Hornet Dynamics
E-commerce Development Services- Hornet DynamicsE-commerce Development Services- Hornet Dynamics
E-commerce Development Services- Hornet Dynamics
 
Vitthal Shirke Java Microservices Resume.pdf
Vitthal Shirke Java Microservices Resume.pdfVitthal Shirke Java Microservices Resume.pdf
Vitthal Shirke Java Microservices Resume.pdf
 
OpenMetadata Community Meeting - 5th June 2024
OpenMetadata Community Meeting - 5th June 2024OpenMetadata Community Meeting - 5th June 2024
OpenMetadata Community Meeting - 5th June 2024
 
socradar-q1-2024-aviation-industry-report.pdf
socradar-q1-2024-aviation-industry-report.pdfsocradar-q1-2024-aviation-industry-report.pdf
socradar-q1-2024-aviation-industry-report.pdf
 
GreenCode-A-VSCode-Plugin--Dario-Jurisic
GreenCode-A-VSCode-Plugin--Dario-JurisicGreenCode-A-VSCode-Plugin--Dario-Jurisic
GreenCode-A-VSCode-Plugin--Dario-Jurisic
 
Mobile App Development Company In Noida | Drona Infotech
Mobile App Development Company In Noida | Drona InfotechMobile App Development Company In Noida | Drona Infotech
Mobile App Development Company In Noida | Drona Infotech
 
Energy consumption of Database Management - Florina Jonuzi
Energy consumption of Database Management - Florina JonuziEnergy consumption of Database Management - Florina Jonuzi
Energy consumption of Database Management - Florina Jonuzi
 
8 Best Automated Android App Testing Tool and Framework in 2024.pdf
8 Best Automated Android App Testing Tool and Framework in 2024.pdf8 Best Automated Android App Testing Tool and Framework in 2024.pdf
8 Best Automated Android App Testing Tool and Framework in 2024.pdf
 
Introducing Crescat - Event Management Software for Venues, Festivals and Eve...
Introducing Crescat - Event Management Software for Venues, Festivals and Eve...Introducing Crescat - Event Management Software for Venues, Festivals and Eve...
Introducing Crescat - Event Management Software for Venues, Festivals and Eve...
 
Automated software refactoring with OpenRewrite and Generative AI.pptx.pdf
Automated software refactoring with OpenRewrite and Generative AI.pptx.pdfAutomated software refactoring with OpenRewrite and Generative AI.pptx.pdf
Automated software refactoring with OpenRewrite and Generative AI.pptx.pdf
 
WWDC 2024 Keynote Review: For CocoaCoders Austin
WWDC 2024 Keynote Review: For CocoaCoders AustinWWDC 2024 Keynote Review: For CocoaCoders Austin
WWDC 2024 Keynote Review: For CocoaCoders Austin
 
A Study of Variable-Role-based Feature Enrichment in Neural Models of Code
A Study of Variable-Role-based Feature Enrichment in Neural Models of CodeA Study of Variable-Role-based Feature Enrichment in Neural Models of Code
A Study of Variable-Role-based Feature Enrichment in Neural Models of Code
 
Lecture 2 - software testing SE 412.pptx
Lecture 2 - software testing SE 412.pptxLecture 2 - software testing SE 412.pptx
Lecture 2 - software testing SE 412.pptx
 
Graspan: A Big Data System for Big Code Analysis
Graspan: A Big Data System for Big Code AnalysisGraspan: A Big Data System for Big Code Analysis
Graspan: A Big Data System for Big Code Analysis
 
Measures in SQL (SIGMOD 2024, Santiago, Chile)
Measures in SQL (SIGMOD 2024, Santiago, Chile)Measures in SQL (SIGMOD 2024, Santiago, Chile)
Measures in SQL (SIGMOD 2024, Santiago, Chile)
 
Oracle Database 19c New Features for DBAs and Developers.pptx
Oracle Database 19c New Features for DBAs and Developers.pptxOracle Database 19c New Features for DBAs and Developers.pptx
Oracle Database 19c New Features for DBAs and Developers.pptx
 
Neo4j - Product Vision and Knowledge Graphs - GraphSummit Paris
Neo4j - Product Vision and Knowledge Graphs - GraphSummit ParisNeo4j - Product Vision and Knowledge Graphs - GraphSummit Paris
Neo4j - Product Vision and Knowledge Graphs - GraphSummit Paris
 
UI5con 2024 - Keynote: Latest News about UI5 and it’s Ecosystem
UI5con 2024 - Keynote: Latest News about UI5 and it’s EcosystemUI5con 2024 - Keynote: Latest News about UI5 and it’s Ecosystem
UI5con 2024 - Keynote: Latest News about UI5 and it’s Ecosystem
 
Oracle 23c New Features For DBAs and Developers.pptx
Oracle 23c New Features For DBAs and Developers.pptxOracle 23c New Features For DBAs and Developers.pptx
Oracle 23c New Features For DBAs and Developers.pptx
 
openEuler Case Study - The Journey to Supply Chain Security
openEuler Case Study - The Journey to Supply Chain SecurityopenEuler Case Study - The Journey to Supply Chain Security
openEuler Case Study - The Journey to Supply Chain Security
 

Start using PHP 7

  • 1. START USING PHP 7.X Oscar Merida, @omerida August 1, 2017
  • 3. PHP 5.6 IS EOL PHP 5 released July 2004 php 5.6: security xes through Dec. 31, 2018 Active support for 5.6 ended Jan 19, 2017. It’s worth noting the last signigicant version of PHP 5 was released Aug. 2014, almost 3 years ago. If you have an older applicaiton or clients with one, use a proactive approach. Don’t wait until something bad happens and then blame them for not upgrading.
  • 4. VULNERABILITIES IN PHP lists 555 vulnerabilities for PHP.cvedetails.com This does not mean PHP 7 is vulnerability free or that PHP 5 is riddled with them. It just means the PHP core team is not fixing vulnerabilities in versions prior to 5.6. After this year, they will only fix PHP 7. You’re distributions may back-port fixes to older versions, so you may have more time.
  • 5. PHP 7 USES LESS MEMORY A signi cant amount of work went into optimizing how the Zend Engine manages memory. Packed and Immutable Arrays consume less memory. Reduced memory allocations for variables. Smarter reference handling. The Zend Engine is the name given to the PHP interpreter by Zeev Suraski and Andi Gutman shipped with PHP 4. Packed arrays are arrays with numeric indexes, in order. Immutable arrays contain values which don’t change like integers, strings, other immutable arrays.
  • 6. AS A RESULT, IT USES LESS CPU Performs fewer memory operations Optimize how variables in strings are interpolated The black re.io blog has a series detailing the changes in the Zend Engine.
  • 7. PHP 7 IS LESS RESOURCE INTENSIVE Less memory, CPU means == Need Fewer, less powerful servers.
  • 8. As we’ll see, this can be a powerful argument to your boss or CFO in making a case for upgrading. BENCHMARKS for PHP 7:Zend benchmarks Drupal 7: 316 vs 182 req/sec Drupal 8: 55 vs 32 From by Rasmus LerdorfSpeeding up the Web with PHP 7 Drupal 8: 2,580 reqs/s vs. 1,401 WordPress: 604 vs 270 Zend, the company started by Zeev and Andi, provided an infographic showing the improvements they measured. Also, Rasmus Lerdorf, the original creator of PHP, has a talk detailing and measuring the performance improvements.
  • 9. IN PRODUCTION: BADOO switching to PHP 7 saved $1M.Baddoo.com estimates Badoo is a social discovery network. Visit this link for real-world data. In summary, they reduced response time by 40%, overall load on their clusters fell below 50%, and memory usage reduced to 1/8th. Allows them to save costs by eliminating need for 400 servers, half of their machines.
  • 10. IN PRODUCTION: DAILY MOTION We can handle twice more traf c, with the same infrastructure. PHP 7 deployment at Dailymotion Dailymotion is a video sharing cite. They used etsy/phan to identify incompatibilities. According to them, it took less than a week
  • 11. to migrate their codebase. NEW LANGUAGE FEATURES
  • 12. SCALAR TYPE HINTS function getRecord(int $id) { // use integer $id to lookup item from DB } function concatNames(string $first, string $last) { return $first . ' ' . $last; } PHP 5 had typehints for arrays, callables, classes, and interface. PHP 7 adds it for scalar values. Remove boilerplate code to check if parameters are valid.
  • 13. SCALAR TYPE HINT: Enable strict mode to enforce them. <?php declare(strict_types = 1); // ... // if $id isn't a string, throws an error $record = $db->getRecord($id); php.net: Strict Typing Emphasize the calling code has to enable it. In strict mode, throws exceptions if types don’t match. Otherwise, the Zend Engine will convert it automatically for you. As a result, int, bool, string, float are now reserved words. You can’t have classes or functions with the same name.
  • 14. COERCING VALUES If not in strict mode, PHP tries to convert a variable to the de ned type. Type declaration int oat string bool object int yes yes* yes† yes no oat yes yes yes† yes no string yes yes yes yes yes‡ bool yes yes yes yes no
  • 15. RETURN TYPE HINTS function getRecord(int $id) : PersonRecord { // use integer $id to lookup item from DB } function concatNames(string $first, string $last) : string { return $first . ' ' . $last; } As with type hinting, in strict mode will throw errors. For static types, they’ll be coerced into the correct type. For example, integers will be turned to strings, etc.
  • 16. ENGINE EXCEPTIONS Almost all errors are now catchable exceptions. It’s now possible to catch almost all errors PHP may encounter and handle them gracefully.
  • 17. NEW OPERATORS 1. Spaceship operator <=> $a <=> $b 2. Null coallesce operator ?? $name = $user['name'] ?? 'anonymous'; These operators introduce syntactic sugar to make code you write more concise. The spaceship operator compares two values, returns -1, 0, 1. Useful for custom sorting functions. The null coallesce operator assigns a default value if the expected one is not set.
  • 18. UNIFORM VARIABLE SYNTAX $field['name' => 'my_field', 'value' => 'target_id']; $node->$field['value']; // $node->{$field['value']}; // PHP 5 $node->target_id; // {$node->$field}['value']; // PHP 7 error, $field is not a string PHP 7 is consistent when evaluating variables by interpreting them from left to right. If you have some tricky usages of variables within variables, use curly braces to explicitly set the order.
  • 19. OTHER CHANGES PHP 7.1: nullable type and void return types. function doSomething(?string input): ?string PHP 7.2: libsodium support Nullable types and void return allow you to make these optional. No error thrown if they are missing. Libsodium adds modern cryptography support into core. Aim is to provide high quality crypto functions.
  • 20. REMOVED FUNCTIONALITY PHP 7 did remove features marked as deprecated in PHP 5. Hence the version bump. PHP RFC: Removed deprecated functionality Leading up to PHP 7’s release, an RFC lists all the functionality to be removed. These were already things marked as
  • 21. deprecated in PHP 5. MYSQL Old mysql_ family of functions removed Update code to use PDO and prepared statements mysqli extension is also an option This change won’t affect Drupal but if you have custom databases, it’s time to modernize your code.
  • 22. ALSO REMOVED ASP and Script tags <% and <script language="php"> ereg_ regular expressions. Use preg_ functions magic_quotes functionality Some iconv.* and mbstring.* php.ini settings preg_replace() eval modi er
  • 23. Many more things were removed in PHP 7 to prevent errors, enhance security, or remove seldom-used features. NEW DEPRECATED Develop with E_DEPRECATED and E_NOTICES on to see and x these errors. Includes: PHP 4 style constructors. Static calls to non-static methods. ext/mcrypt extension. See Deprecated features in PHP 7.0 Marking some things for removal in PHP 8.
  • 25. TEST YOUR SITE Identify code which needs to be updated. Ideally, have a test suite to check for failures. If you don’t already have a test suite, this would be a good time in investing in one (cover critical paths)
  • 26. READ THE MIGRATION GUIDE php.net has a guide forMigrating from PHP 5.6.x to PHP 7.0.x Lists BC changes Lists Changed and new functions. Removed Extensions and SAPIs I’ve given you an overview of the major features and changes in PHP 7.0. This guide is the canonical reference listing all of them. You should read it before you update your own applicaitons.
  • 27. DRUPAL CORE Drupal 8: Core is PHP 7 compatible Drupal 7: Support PHP 7 Drupal 8 is fully tested and compatible with PHP 7. In fact, Drupal 8 was an important test bed for for candidate releases of PHP 7. While there are tickets open for D7, ensure you’re using at least 7.50.
  • 28. DRUPAL MODULES Update contrib modules to include PHP 7 support. Webform Backup & Migrate As usual, PHP 7 support in contrib is harder to guarantee. Becuase of the efforts to maintain BC, most modules should work with little or no changes. Many might throw new deprecation notices (php4 style constructors where the class name matches a function name)
  • 29. STATIC ANALYZERS Automatically scan your codebase and nd code which needs to be upgraded : tests for PHP7/PHP5 backward compatibility (and more) : has compatibility tests too. : From 5.3+ etsy/phan exakat Preparing Legacy Applications for PHP 7 with Phan monque/PHP-Migration These tools will automatically inspect your codebase to look for backwards incompatibility breaks. You’ll need to install the php- ast extenstion for etsy/phan. Exakat depends on gremlin, neo4 packages.
  • 30. PRE-BUILT ENVIRONMENTS : PHP 7.1. Drupal focused, PHP 7.1 for PHP 7.0, 7.1, 7.2 Homestead DrupalVM Docker images Laravel’s Homestead gives you an easy-to-configure LAMP environment. DrupalVM provides a lot, useful if you have many dependent services like Solr. You can configure it to use PHP 5.6, 7.0, or 7.1. Docker provides official PHP 7 images, more performant than Vagrant.
  • 31. DISTROS WITH PHP7 Debian stable has PHP 7.0, use for older releases. Ubuntu 16.04 LTS has PHP 7.0 Redhat EL: Via Software Collections or 3rd part repos. Centos 7: from Remi, Webtatic, and IUS dotdeb Precompiled packages
  • 33. PHP 7… …brings massive performance gains and improvements to the language to help you write better code. There’s no reason to stay on PHP 5.
  • 34. THANK YOU @omerida I publish php[architect], a monthly magazine for PHP developers. Check it out: www.phparch.com php[world] is our fall conference in Tyson’s Corner. world.phparch.com