SlideShare une entreprise Scribd logo
1  sur  27
Migrating to PHP 7
John Coggeshall – International PHP Conference, 2016
Berlin, Germany
@coogle, john@coggeshall.org
Who’s This Guy?
• The Author of ext/tidy
• (primary) Author in (almost) 5 books on PHP going from PHP 4 to
PHP 7
• Speaking at conferences for a long time
!!!!!
circa 2004 today
Major Concerns when Migrating to PHP 7
• Error Handling
• Variable Handling
• Control Structure Changes
• Removed Features / Changed Functions
• Newly Deprecated Behaviors
• This talk will not cover every single detail of the changes in PHP 7.
That’s what Migration Documentation is for:
http://php.net/manual/de/migration70.php
Error Handling
• One of the biggest breaks you may have to deal with migrating to
PHP 7 will be error handling
• Especially when using Custom Error Handlers
• Many fatal / recoverable errors from PHP 5 have been converted
to exceptions
• Major Break: The callback for set_exception_handler() is not
guaranteed to receive Exception objects
Fixing Exception Handlers
<?php
function my_handler(Exception $e)
{
/* ... */
}
<?php
function my_handler(Throwable $e)
{
/* ... */
}
PHP 5 PHP 7
Other Internal Exceptions
• Some internal class constructors in PHP 5 would create objects in
unusable states rather than throw exceptions
• In PHP 7 all class constructors throw exceptions
• Notably this was a problem in some of the Reflection Classes
You should always be prepared to handle an exception thrown from
PHP 7 internal classes in the event something goes wrong
Parser Errors
• In PHP 5, parsing errors (for instance, from an include_once
statement) would cause a fatal error
• In PHP 7 parser errors throw the new ParseError exception
Again, your custom error handlers and exception handlers may need
updating to reflect this new behavior
E_STRICT is Dead
Situation New Behavior
Indexing by a Resource E_NOTICE
Abstract Static Methods No Error
”Redefining” a constructor No Error
Signature mismatch during inheritance E_WARNING
Same (compatible) property used in two
traits
No Error
Accessing a static property non-statically E_NOTICE
Only variables should be assigned by
reference
E_NOTICE
Only variables should be passed by reference E_NOTICE
Calling non-static methods statically E_DEPRECATED
Indirect Variables, Properties, Methods
• In PHP 5 complex indirect access to variables, properties, etc. was
not consistently handled.
• PHP 7 addresses these inconsistencies, at the cost of backward
compatibility
Typically most well-written code will not be affected by this.
However, if you have complicated indirect accesses you may hit
this.
Indirect Variables, Properties, Methods
Expression PHP 5 PHP 7
$$foo[‘bar’][‘baz’] ${$foo[‘bar’][‘baz’]} ($$foo)[‘bar’][‘baz’]
$foo->$bar[‘baz’] $foo->{$bar[‘baz’]} ($foo->$bar)[‘baz’]
$foo->$bar[‘baz’]() $foo->{$bar[‘baz’]}() ($foo->$bar)[‘baz’]()
Foo::bar[‘baz’]() Foo::{$bar[‘baz’]}() (Foo::$bar)[‘baz’]()
If you are using any of the expression patterns on the left
column the code will need to be updated to the middle
“PHP 5” column to be interpreted correctly.
list() Mayhem
• There is a lot of code out there that takes the assignment order of
the list() statement for granted:
<?php
list($x[], $x[]) = [1, 2];
// $x = [2, 1] in PHP 5
// $x = [1, 2] in PHP 7
• This was never a good idea and you should not rely on the order in
this fashion.
list() Mayhem
• Creative use of the list() statement with empty assignments will
also now break
<?php
// Both will now break in PHP 7
list() = $array;
list(,$x) = $array;
list() Mayhem
• Finally, list() can no longer be used to unpack strings.
<?php
list($a, $b, $c) = “abc”;
// $a = “a” in PHP 5, breaks in PHP 7
Subtle foreach() changes – Array Pointers
• In PHP 5 iterating over an array using foreach() would cause the
internal array pointer to move for each iteration
<?php
$a = [1, 2]
foreach($a as &$val) {
var_dump(current($a));
}
// Output in PHP 5:
// int(1)
// int(2)
// bool(false)
<?php
$a = [1, 2]
foreach($a as &$val) {
var_dump(current($a));
}
// Output in PHP 7:
// int(1)
// int(1)
// int(1)
Subtle foreach() changes – References
This subtle change may break code that modifies arrays by
reference during an iteration of it
<?php
$a = [0];
foreach($a as &$val) {
var_dump($val);
$a[1] = 1;
}
// Output in PHP 5
// int(0)
<?php
$a = [0];
foreach($a as &$val) {
var_dump($val);
$a[1] = 1;
}
// Output in PHP 7
// int(0)
// int(1)
In PHP 5 you couldn’t add to an array, even when passing it by
reference and iterate over them in the same block
Integer handler changes
• Invalid Octal literals now throw parser errors instead of being
silently ignored
• Bitwise shifts of integers by negative numbers now throws an
ArithmeticError
• Bitwise shifts that are out of range will now always be int(0)
rather than being architecture-dependent
Division By Zero
• In PHP 5 Division by Zero would always cause an E_WARNING and
evaluate to int(0), including attempting to do a modulus (%) by
zero
• In PHP 7
• X / 0 == float(INF)
• 0 / 0 == float(NaN)
• Attempting to do a modulus of zero now causes a
DivisionByZeroError exception to be thrown
Hexadecimals and Strings
• In PHP 5 strings that evaluated to hexadecimal values could be
cast to numeric values
• I.e. (int)“0x123” == 291
• In PHP 7 strings are no longer directly interpretable as numeric
values
• I.e. (int)”0x123” == 0
• If you need to convert a string hexadecimal value to its integer
equivalent you can use filter_var() with the FILTER_VALIDATE_INT
and FILTER_FLAG_ALLOW_HEX options to convert it to an integer
value.
Calls from Incompatible Contexts
• Static calls made to a non-static method with an incompatible
context (i.e. calling a non-static method statically in a completely
unrelated class) has thrown a E_DEPRECATED error since 5.6
• I.e. Class A calls a non-static method in Class B statically
• In PHP 5, $this would still be defined pointing to class A
• In PHP 7, $this is no longer defined
yield is now right associative
• In PHP 5 the yield construct no longer requires parentheses and
has been changed to a right associative operator
<?php // PHP 5
echo yield -1; // (yield) – 1;
yield $foo or die // yield ($foo or die)
<?php // PHP 7
echo yield -1; // yield (-1)
yield $foo or die // (yield $foo) or die;
Misc Incompatibilities
• There are a number of other (smaller) incompatibilities between
PHP 5 and PHP 7 worth mentioning
• ASP-style tags <% %> have been removed
• <script language=“php”> style tags have been removed
• Assigning the result of the new statement by reference is now fatal error
• Functions that have multiple parameters with the same name is now a
compile error
• switch statements with multiple default blocks is now a compile error
• $HTTP_RAW_POST_DATA has been removed in favor of php://input
• # comments in .ini files parsed by PHP are no longer supported (use
semicolon)
• Custom session handlers that return false result in fatal errors now
Removed Functions
• Numerous functions have been removed in PHP 7 and replaced
with better equivalents where appropriate
Variable Functions
call_user_method()
call_user_method_array()
Mcrypt
mcrypt_generic_end()
mcrypt_ecb()
mcrypt_cbc()
mcrypt_cfb()
mcrypt_ofb()
Intl
datefmt_set_timezone_id()
IntlDateFormatter::setTimeZoneId()
System
set_magic_quotes_runtime()
magic_quotes_runtime()
set_socket_blocking()
dl() (in PHP-FPM)
=
GD
imagepsbbox()
imagepsencodefont()
imagepsextendfont()
imagepsfreefont()
imagepsloadfont()
imagepsslantfont()
imagepstext()
• Removed Extensions: ereg, mssql, mysql, sybase_ct
Removed Server APIs (SAPIs) and extensions
• Numerous Server APIs (SAPIs) have been removed from PHP 7:
• aolserver
• apache
• apache_hooks
• apache2filter
• caudium
• continunity
• isapi
• milter
• nsapi
• phttpd
• pi3web
• roxen
• thttpd
• tux
• webjames
Deprecated Features
• A number of things have been deprecated in PHP 7, which means
they will now throw E_DEPRECATED errors if you happen to be
using them in your code
• PHP 4 style constructors
• Static calls to non-static methods
• Passing your own salt to the password_hash() function
• capture_session_meta SSL context option
• For now these errors can be suppressed (using the @ operator) but
the code should be updated as necessary.
Changes to Core Functions
• When migrating from PHP 5 to PHP 7 there are a few functions
that have changed behaviors worth noting
• mktime() and gmmktime() no longer accept the $is_dst parameter
• preg_replace() no longer supports the /e modifier and
preg_replace_callback() must now be used
• setlocale() no longer accepts strings for the $category parameter. The
LC_* constants must be used
• substr() now returns an empty string if then $string parameter is as
long as the $start parameter value.
Name Conflicts
• There are a lot of new things in PHP 7 that didn’t exist in PHP 5
• New Functions
• New Methods
• New Classes
• New Constants
• New Exceptions
• You should review the PHP Migration documentation for what’s
been added to determine if any code you’ve written now conflicts
with something internal to PHP 7
• For example, do you have an IntlChar class in your application?
Thank you!
John Coggeshall
john@coggeshall.org, @coolge

Contenu connexe

Tendances (20)

Design attern in php
Design attern in phpDesign attern in php
Design attern in php
 
Object Oriented Design Patterns for PHP
Object Oriented Design Patterns for PHPObject Oriented Design Patterns for PHP
Object Oriented Design Patterns for PHP
 
PHP Comprehensive Overview
PHP Comprehensive OverviewPHP Comprehensive Overview
PHP Comprehensive Overview
 
Yapc::NA::2009 - Command Line Perl
Yapc::NA::2009 - Command Line PerlYapc::NA::2009 - Command Line Perl
Yapc::NA::2009 - Command Line Perl
 
Php Crash Course - Macq Electronique 2010
Php Crash Course - Macq Electronique 2010Php Crash Course - Macq Electronique 2010
Php Crash Course - Macq Electronique 2010
 
PHP
PHPPHP
PHP
 
9780538745840 ppt ch01 PHP
9780538745840 ppt ch01 PHP9780538745840 ppt ch01 PHP
9780538745840 ppt ch01 PHP
 
9780538745840 ppt ch02
9780538745840 ppt ch029780538745840 ppt ch02
9780538745840 ppt ch02
 
Introduction to php basics
Introduction to php   basicsIntroduction to php   basics
Introduction to php basics
 
Flowex - Railway Flow-Based Programming with Elixir GenStage.
Flowex - Railway Flow-Based Programming with Elixir GenStage.Flowex - Railway Flow-Based Programming with Elixir GenStage.
Flowex - Railway Flow-Based Programming with Elixir GenStage.
 
PHP traits, treat or threat?
PHP traits, treat or threat?PHP traits, treat or threat?
PHP traits, treat or threat?
 
Php
PhpPhp
Php
 
STC 2016 Programming Language Storytime
STC 2016 Programming Language StorytimeSTC 2016 Programming Language Storytime
STC 2016 Programming Language Storytime
 
php basics
php basicsphp basics
php basics
 
PHP - Introduction to PHP
PHP -  Introduction to PHPPHP -  Introduction to PHP
PHP - Introduction to PHP
 
Php tutorial
Php tutorialPhp tutorial
Php tutorial
 
Introduction to php php++
Introduction to php php++Introduction to php php++
Introduction to php php++
 
php app development 1
php app development 1php app development 1
php app development 1
 
Php basics
Php basicsPhp basics
Php basics
 
PHP 7 Crash Course
PHP 7 Crash CoursePHP 7 Crash Course
PHP 7 Crash Course
 

En vedette

Presentación
PresentaciónPresentación
Presentacióngbarbuto
 
IRCA 2020-OHSMS Lead Auditor training-A16830
IRCA 2020-OHSMS Lead Auditor training-A16830IRCA 2020-OHSMS Lead Auditor training-A16830
IRCA 2020-OHSMS Lead Auditor training-A16830Laxman Waykar
 
Instructivo mcbc valorizacion stocks
Instructivo mcbc   valorizacion stocksInstructivo mcbc   valorizacion stocks
Instructivo mcbc valorizacion stocksricardopabloasensio
 
(BPI-II) Unidad 14 - ( Planificación producción -PP) - transacciones
(BPI-II) Unidad 14 - ( Planificación producción -PP) - transacciones(BPI-II) Unidad 14 - ( Planificación producción -PP) - transacciones
(BPI-II) Unidad 14 - ( Planificación producción -PP) - transaccionesSebastian Triviño Ortega
 
Iso 22716 Aplicación Practica de la Norma
Iso 22716 Aplicación Practica de la NormaIso 22716 Aplicación Practica de la Norma
Iso 22716 Aplicación Practica de la Normapgomezlobo
 
Transacciones de visualizacion de stock doc
Transacciones de visualizacion de stock docTransacciones de visualizacion de stock doc
Transacciones de visualizacion de stock docricardopabloasensio
 
Kpi for internal audit
Kpi for internal auditKpi for internal audit
Kpi for internal auditsolutesarrobin
 
planificacion-de-necesidades-sobre-consumo
planificacion-de-necesidades-sobre-consumoplanificacion-de-necesidades-sobre-consumo
planificacion-de-necesidades-sobre-consumoJUVER ALFARO
 
Internal audit manager performance appraisal
Internal audit manager performance appraisalInternal audit manager performance appraisal
Internal audit manager performance appraisalcollinsbruce43
 
Plantilla gerencia-de-proyectos
Plantilla gerencia-de-proyectosPlantilla gerencia-de-proyectos
Plantilla gerencia-de-proyectosDavid Toyohashi
 
Sap mm
Sap mmSap mm
Sap mmediaz9
 
Planificación de Requerimientos de Material (MRP)
Planificación de Requerimientos de Material (MRP)Planificación de Requerimientos de Material (MRP)
Planificación de Requerimientos de Material (MRP)judadd
 
Cosmetic gmp induction training
Cosmetic gmp induction trainingCosmetic gmp induction training
Cosmetic gmp induction trainingMike Izon
 
Las normas su importancia y evolucion
Las normas su importancia y evolucionLas normas su importancia y evolucion
Las normas su importancia y evolucionZitec Consultores
 

En vedette (20)

Disntinciones
Disntinciones Disntinciones
Disntinciones
 
Presentación
PresentaciónPresentación
Presentación
 
IRCA 2020-OHSMS Lead Auditor training-A16830
IRCA 2020-OHSMS Lead Auditor training-A16830IRCA 2020-OHSMS Lead Auditor training-A16830
IRCA 2020-OHSMS Lead Auditor training-A16830
 
Nueva UNE ISO 9001:2015
Nueva UNE ISO 9001:2015Nueva UNE ISO 9001:2015
Nueva UNE ISO 9001:2015
 
Sap pp parte3
Sap pp parte3Sap pp parte3
Sap pp parte3
 
Instructivo mcbc valorizacion stocks
Instructivo mcbc   valorizacion stocksInstructivo mcbc   valorizacion stocks
Instructivo mcbc valorizacion stocks
 
(BPI-II) Unidad 14 - ( Planificación producción -PP) - transacciones
(BPI-II) Unidad 14 - ( Planificación producción -PP) - transacciones(BPI-II) Unidad 14 - ( Planificación producción -PP) - transacciones
(BPI-II) Unidad 14 - ( Planificación producción -PP) - transacciones
 
Iso 22716 Aplicación Practica de la Norma
Iso 22716 Aplicación Practica de la NormaIso 22716 Aplicación Practica de la Norma
Iso 22716 Aplicación Practica de la Norma
 
Transacciones de visualizacion de stock doc
Transacciones de visualizacion de stock docTransacciones de visualizacion de stock doc
Transacciones de visualizacion de stock doc
 
Kpi for internal audit
Kpi for internal auditKpi for internal audit
Kpi for internal audit
 
planificacion-de-necesidades-sobre-consumo
planificacion-de-necesidades-sobre-consumoplanificacion-de-necesidades-sobre-consumo
planificacion-de-necesidades-sobre-consumo
 
Internal audit manager performance appraisal
Internal audit manager performance appraisalInternal audit manager performance appraisal
Internal audit manager performance appraisal
 
Plantilla gerencia-de-proyectos
Plantilla gerencia-de-proyectosPlantilla gerencia-de-proyectos
Plantilla gerencia-de-proyectos
 
Sap mm
Sap mmSap mm
Sap mm
 
Normas (estándares) ISO relativas a TICs
Normas (estándares) ISO relativas a TICsNormas (estándares) ISO relativas a TICs
Normas (estándares) ISO relativas a TICs
 
Planificación de Requerimientos de Material (MRP)
Planificación de Requerimientos de Material (MRP)Planificación de Requerimientos de Material (MRP)
Planificación de Requerimientos de Material (MRP)
 
Cosmetic gmp induction training
Cosmetic gmp induction trainingCosmetic gmp induction training
Cosmetic gmp induction training
 
GMP - ISO 22716
GMP - ISO 22716GMP - ISO 22716
GMP - ISO 22716
 
NORMA ISO 90003
NORMA ISO 90003NORMA ISO 90003
NORMA ISO 90003
 
Las normas su importancia y evolucion
Las normas su importancia y evolucionLas normas su importancia y evolucion
Las normas su importancia y evolucion
 

Similaire à Migrating to PHP 7

What To Expect From PHP7
What To Expect From PHP7What To Expect From PHP7
What To Expect From PHP7Codemotion
 
Preparing code for Php 7 workshop
Preparing code for Php 7 workshopPreparing code for Php 7 workshop
Preparing code for Php 7 workshopDamien Seguy
 
Damien seguy php 5.6
Damien seguy php 5.6Damien seguy php 5.6
Damien seguy php 5.6Damien Seguy
 
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.4Wim Godden
 
Last train to php 7
Last train to php 7Last train to php 7
Last train to php 7Damien Seguy
 
Php7 HHVM and co
Php7 HHVM and coPhp7 HHVM and co
Php7 HHVM and coweltling
 
Php7 hhvm and co
Php7 hhvm and coPhp7 hhvm and co
Php7 hhvm and coPierre Joye
 
PHP from soup to nuts Course Deck
PHP from soup to nuts Course DeckPHP from soup to nuts Course Deck
PHP from soup to nuts Course DeckrICh morrow
 
Php7 傳說中的第七隻大象
Php7 傳說中的第七隻大象Php7 傳說中的第七隻大象
Php7 傳說中的第七隻大象bobo52310
 
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 beneluxDamien Seguy
 
Giới thiệu PHP 7
Giới thiệu PHP 7Giới thiệu PHP 7
Giới thiệu PHP 7ZendVN
 
Preparing for the next PHP version (5.6)
Preparing for the next PHP version (5.6)Preparing for the next PHP version (5.6)
Preparing for the next PHP version (5.6)Damien Seguy
 
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 extensionsMark Baker
 
Flying under the radar
Flying under the radarFlying under the radar
Flying under the radarMark Baker
 
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 7Wim Godden
 

Similaire à Migrating to PHP 7 (20)

What To Expect From PHP7
What To Expect From PHP7What To Expect From PHP7
What To Expect From PHP7
 
Preparing code for Php 7 workshop
Preparing code for Php 7 workshopPreparing code for Php 7 workshop
Preparing code for Php 7 workshop
 
Peek at PHP 7
Peek at PHP 7Peek at PHP 7
Peek at PHP 7
 
Damien seguy php 5.6
Damien seguy php 5.6Damien seguy php 5.6
Damien seguy php 5.6
 
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
 
Last train to php 7
Last train to php 7Last train to php 7
Last train to php 7
 
Php7 HHVM and co
Php7 HHVM and coPhp7 HHVM and co
Php7 HHVM and co
 
Php7 hhvm and co
Php7 hhvm and coPhp7 hhvm and co
Php7 hhvm and co
 
PHP from soup to nuts Course Deck
PHP from soup to nuts Course DeckPHP from soup to nuts Course Deck
PHP from soup to nuts Course Deck
 
Php7 傳說中的第七隻大象
Php7 傳說中的第七隻大象Php7 傳說中的第七隻大象
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
 
PHP7: Hello World!
PHP7: Hello World!PHP7: Hello World!
PHP7: Hello World!
 
Giới thiệu PHP 7
Giới thiệu PHP 7Giới thiệu PHP 7
Giới thiệu PHP 7
 
Preparing for the next PHP version (5.6)
Preparing for the next PHP version (5.6)Preparing for the next PHP version (5.6)
Preparing for the next PHP version (5.6)
 
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
 
Flying under the radar
Flying under the radarFlying under the radar
Flying under the radar
 
PHP 7
PHP 7PHP 7
PHP 7
 
What's new with PHP7
What's new with PHP7What's new with PHP7
What's new with PHP7
 
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
 
Prersentation
PrersentationPrersentation
Prersentation
 

Plus de John Coggeshall

Virtualization for Developers
Virtualization for DevelopersVirtualization for Developers
Virtualization for DevelopersJohn Coggeshall
 
ZF2 Modules: Events, Services, and of course, modularity
ZF2 Modules: Events, Services, and of course, modularityZF2 Modules: Events, Services, and of course, modularity
ZF2 Modules: Events, Services, and of course, modularityJohn Coggeshall
 
PHP Development for Google Glass using Phass
PHP Development for Google Glass using PhassPHP Development for Google Glass using Phass
PHP Development for Google Glass using PhassJohn Coggeshall
 
Virtualization for Developers
Virtualization for DevelopersVirtualization for Developers
Virtualization for DevelopersJohn Coggeshall
 
Development with Vagrant
Development with VagrantDevelopment with Vagrant
Development with VagrantJohn Coggeshall
 
Introduction to Zend Framework 2
Introduction to Zend Framework 2Introduction to Zend Framework 2
Introduction to Zend Framework 2John Coggeshall
 
10 things not to do at a Startup
10 things not to do at a Startup10 things not to do at a Startup
10 things not to do at a StartupJohn Coggeshall
 
Virtualization for Developers
Virtualization for DevelopersVirtualization for Developers
Virtualization for DevelopersJohn Coggeshall
 
Building PHP Powered Android Applications
Building PHP Powered Android ApplicationsBuilding PHP Powered Android Applications
Building PHP Powered Android ApplicationsJohn Coggeshall
 
Ria Applications And PHP
Ria Applications And PHPRia Applications And PHP
Ria Applications And PHPJohn Coggeshall
 
Apache Con 2008 Top 10 Mistakes
Apache Con 2008 Top 10 MistakesApache Con 2008 Top 10 Mistakes
Apache Con 2008 Top 10 MistakesJohn Coggeshall
 
Ria Development With Flex And PHP
Ria Development With Flex And PHPRia Development With Flex And PHP
Ria Development With Flex And PHPJohn Coggeshall
 
Top 10 Scalability Mistakes
Top 10 Scalability MistakesTop 10 Scalability Mistakes
Top 10 Scalability MistakesJohn Coggeshall
 
Enterprise PHP: A Case Study
Enterprise PHP: A Case StudyEnterprise PHP: A Case Study
Enterprise PHP: A Case StudyJohn Coggeshall
 
Building Dynamic Web Applications on i5 with PHP
Building Dynamic Web Applications on i5 with PHPBuilding Dynamic Web Applications on i5 with PHP
Building Dynamic Web Applications on i5 with PHPJohn Coggeshall
 
Migrating from PHP 4 to PHP 5
Migrating from PHP 4 to PHP 5Migrating from PHP 4 to PHP 5
Migrating from PHP 4 to PHP 5John Coggeshall
 

Plus de John Coggeshall (20)

Virtualization for Developers
Virtualization for DevelopersVirtualization for Developers
Virtualization for Developers
 
ZF2 Modules: Events, Services, and of course, modularity
ZF2 Modules: Events, Services, and of course, modularityZF2 Modules: Events, Services, and of course, modularity
ZF2 Modules: Events, Services, and of course, modularity
 
PHP Development for Google Glass using Phass
PHP Development for Google Glass using PhassPHP Development for Google Glass using Phass
PHP Development for Google Glass using Phass
 
Virtualization for Developers
Virtualization for DevelopersVirtualization for Developers
Virtualization for Developers
 
Development with Vagrant
Development with VagrantDevelopment with Vagrant
Development with Vagrant
 
Introduction to Zend Framework 2
Introduction to Zend Framework 2Introduction to Zend Framework 2
Introduction to Zend Framework 2
 
10 things not to do at a Startup
10 things not to do at a Startup10 things not to do at a Startup
10 things not to do at a Startup
 
Virtualization for Developers
Virtualization for DevelopersVirtualization for Developers
Virtualization for Developers
 
Puppet
PuppetPuppet
Puppet
 
Building PHP Powered Android Applications
Building PHP Powered Android ApplicationsBuilding PHP Powered Android Applications
Building PHP Powered Android Applications
 
Ria Applications And PHP
Ria Applications And PHPRia Applications And PHP
Ria Applications And PHP
 
Beyond the Browser
Beyond the BrowserBeyond the Browser
Beyond the Browser
 
Apache Con 2008 Top 10 Mistakes
Apache Con 2008 Top 10 MistakesApache Con 2008 Top 10 Mistakes
Apache Con 2008 Top 10 Mistakes
 
Ria Development With Flex And PHP
Ria Development With Flex And PHPRia Development With Flex And PHP
Ria Development With Flex And PHP
 
Top 10 Scalability Mistakes
Top 10 Scalability MistakesTop 10 Scalability Mistakes
Top 10 Scalability Mistakes
 
Enterprise PHP: A Case Study
Enterprise PHP: A Case StudyEnterprise PHP: A Case Study
Enterprise PHP: A Case Study
 
Building Dynamic Web Applications on i5 with PHP
Building Dynamic Web Applications on i5 with PHPBuilding Dynamic Web Applications on i5 with PHP
Building Dynamic Web Applications on i5 with PHP
 
PHP Security Basics
PHP Security BasicsPHP Security Basics
PHP Security Basics
 
Migrating from PHP 4 to PHP 5
Migrating from PHP 4 to PHP 5Migrating from PHP 4 to PHP 5
Migrating from PHP 4 to PHP 5
 
Ajax and PHP
Ajax and PHPAjax and PHP
Ajax and PHP
 

Dernier

Hot Service (+9316020077 ) Goa Call Girls Real Photos and Genuine Service
Hot Service (+9316020077 ) Goa  Call Girls Real Photos and Genuine ServiceHot Service (+9316020077 ) Goa  Call Girls Real Photos and Genuine Service
Hot Service (+9316020077 ) Goa Call Girls Real Photos and Genuine Servicesexy call girls service in goa
 
Nanded City ( Call Girls ) Pune 6297143586 Hot Model With Sexy Bhabi Ready ...
Nanded City ( Call Girls ) Pune  6297143586  Hot Model With Sexy Bhabi Ready ...Nanded City ( Call Girls ) Pune  6297143586  Hot Model With Sexy Bhabi Ready ...
Nanded City ( Call Girls ) Pune 6297143586 Hot Model With Sexy Bhabi Ready ...tanu pandey
 
Call Now ☎ 8264348440 !! Call Girls in Green Park Escort Service Delhi N.C.R.
Call Now ☎ 8264348440 !! Call Girls in Green Park Escort Service Delhi N.C.R.Call Now ☎ 8264348440 !! Call Girls in Green Park Escort Service Delhi N.C.R.
Call Now ☎ 8264348440 !! Call Girls in Green Park Escort Service Delhi N.C.R.soniya singh
 
How is AI changing journalism? (v. April 2024)
How is AI changing journalism? (v. April 2024)How is AI changing journalism? (v. April 2024)
How is AI changing journalism? (v. April 2024)Damian Radcliffe
 
Call Girls In Saket Delhi 💯Call Us 🔝8264348440🔝
Call Girls In Saket Delhi 💯Call Us 🔝8264348440🔝Call Girls In Saket Delhi 💯Call Us 🔝8264348440🔝
Call Girls In Saket Delhi 💯Call Us 🔝8264348440🔝soniya singh
 
Call Girls Service Chandigarh Lucky ❤️ 7710465962 Independent Call Girls In C...
Call Girls Service Chandigarh Lucky ❤️ 7710465962 Independent Call Girls In C...Call Girls Service Chandigarh Lucky ❤️ 7710465962 Independent Call Girls In C...
Call Girls Service Chandigarh Lucky ❤️ 7710465962 Independent Call Girls In C...Sheetaleventcompany
 
INDIVIDUAL ASSIGNMENT #3 CBG, PRESENTATION.
INDIVIDUAL ASSIGNMENT #3 CBG, PRESENTATION.INDIVIDUAL ASSIGNMENT #3 CBG, PRESENTATION.
INDIVIDUAL ASSIGNMENT #3 CBG, PRESENTATION.CarlotaBedoya1
 
Delhi Call Girls Rohini 9711199171 ☎✔👌✔ Whatsapp Hard And Sexy Vip Call
Delhi Call Girls Rohini 9711199171 ☎✔👌✔ Whatsapp Hard And Sexy Vip CallDelhi Call Girls Rohini 9711199171 ☎✔👌✔ Whatsapp Hard And Sexy Vip Call
Delhi Call Girls Rohini 9711199171 ☎✔👌✔ Whatsapp Hard And Sexy Vip Callshivangimorya083
 
Call Girls In Pratap Nagar Delhi 💯Call Us 🔝8264348440🔝
Call Girls In Pratap Nagar Delhi 💯Call Us 🔝8264348440🔝Call Girls In Pratap Nagar Delhi 💯Call Us 🔝8264348440🔝
Call Girls In Pratap Nagar Delhi 💯Call Us 🔝8264348440🔝soniya singh
 
AWS Community DAY Albertini-Ellan Cloud Security (1).pptx
AWS Community DAY Albertini-Ellan Cloud Security (1).pptxAWS Community DAY Albertini-Ellan Cloud Security (1).pptx
AWS Community DAY Albertini-Ellan Cloud Security (1).pptxellan12
 
DDoS In Oceania and the Pacific, presented by Dave Phelan at NZNOG 2024
DDoS In Oceania and the Pacific, presented by Dave Phelan at NZNOG 2024DDoS In Oceania and the Pacific, presented by Dave Phelan at NZNOG 2024
DDoS In Oceania and the Pacific, presented by Dave Phelan at NZNOG 2024APNIC
 
VIP 7001035870 Find & Meet Hyderabad Call Girls LB Nagar high-profile Call Girl
VIP 7001035870 Find & Meet Hyderabad Call Girls LB Nagar high-profile Call GirlVIP 7001035870 Find & Meet Hyderabad Call Girls LB Nagar high-profile Call Girl
VIP 7001035870 Find & Meet Hyderabad Call Girls LB Nagar high-profile Call Girladitipandeya
 
On Starlink, presented by Geoff Huston at NZNOG 2024
On Starlink, presented by Geoff Huston at NZNOG 2024On Starlink, presented by Geoff Huston at NZNOG 2024
On Starlink, presented by Geoff Huston at NZNOG 2024APNIC
 
GDG Cloud Southlake 32: Kyle Hettinger: Demystifying the Dark Web
GDG Cloud Southlake 32: Kyle Hettinger: Demystifying the Dark WebGDG Cloud Southlake 32: Kyle Hettinger: Demystifying the Dark Web
GDG Cloud Southlake 32: Kyle Hettinger: Demystifying the Dark WebJames Anderson
 
Call Now ☎ 8264348440 !! Call Girls in Sarai Rohilla Escort Service Delhi N.C.R.
Call Now ☎ 8264348440 !! Call Girls in Sarai Rohilla Escort Service Delhi N.C.R.Call Now ☎ 8264348440 !! Call Girls in Sarai Rohilla Escort Service Delhi N.C.R.
Call Now ☎ 8264348440 !! Call Girls in Sarai Rohilla Escort Service Delhi N.C.R.soniya singh
 
Call Girls Ludhiana Just Call 98765-12871 Top Class Call Girl Service Available
Call Girls Ludhiana Just Call 98765-12871 Top Class Call Girl Service AvailableCall Girls Ludhiana Just Call 98765-12871 Top Class Call Girl Service Available
Call Girls Ludhiana Just Call 98765-12871 Top Class Call Girl Service AvailableSeo
 

Dernier (20)

Hot Service (+9316020077 ) Goa Call Girls Real Photos and Genuine Service
Hot Service (+9316020077 ) Goa  Call Girls Real Photos and Genuine ServiceHot Service (+9316020077 ) Goa  Call Girls Real Photos and Genuine Service
Hot Service (+9316020077 ) Goa Call Girls Real Photos and Genuine Service
 
Russian Call Girls in %(+971524965298 )# Call Girls in Dubai
Russian Call Girls in %(+971524965298  )#  Call Girls in DubaiRussian Call Girls in %(+971524965298  )#  Call Girls in Dubai
Russian Call Girls in %(+971524965298 )# Call Girls in Dubai
 
Nanded City ( Call Girls ) Pune 6297143586 Hot Model With Sexy Bhabi Ready ...
Nanded City ( Call Girls ) Pune  6297143586  Hot Model With Sexy Bhabi Ready ...Nanded City ( Call Girls ) Pune  6297143586  Hot Model With Sexy Bhabi Ready ...
Nanded City ( Call Girls ) Pune 6297143586 Hot Model With Sexy Bhabi Ready ...
 
Call Now ☎ 8264348440 !! Call Girls in Green Park Escort Service Delhi N.C.R.
Call Now ☎ 8264348440 !! Call Girls in Green Park Escort Service Delhi N.C.R.Call Now ☎ 8264348440 !! Call Girls in Green Park Escort Service Delhi N.C.R.
Call Now ☎ 8264348440 !! Call Girls in Green Park Escort Service Delhi N.C.R.
 
How is AI changing journalism? (v. April 2024)
How is AI changing journalism? (v. April 2024)How is AI changing journalism? (v. April 2024)
How is AI changing journalism? (v. April 2024)
 
Call Girls In Saket Delhi 💯Call Us 🔝8264348440🔝
Call Girls In Saket Delhi 💯Call Us 🔝8264348440🔝Call Girls In Saket Delhi 💯Call Us 🔝8264348440🔝
Call Girls In Saket Delhi 💯Call Us 🔝8264348440🔝
 
Call Girls Service Chandigarh Lucky ❤️ 7710465962 Independent Call Girls In C...
Call Girls Service Chandigarh Lucky ❤️ 7710465962 Independent Call Girls In C...Call Girls Service Chandigarh Lucky ❤️ 7710465962 Independent Call Girls In C...
Call Girls Service Chandigarh Lucky ❤️ 7710465962 Independent Call Girls In C...
 
INDIVIDUAL ASSIGNMENT #3 CBG, PRESENTATION.
INDIVIDUAL ASSIGNMENT #3 CBG, PRESENTATION.INDIVIDUAL ASSIGNMENT #3 CBG, PRESENTATION.
INDIVIDUAL ASSIGNMENT #3 CBG, PRESENTATION.
 
Rohini Sector 22 Call Girls Delhi 9999965857 @Sabina Saikh No Advance
Rohini Sector 22 Call Girls Delhi 9999965857 @Sabina Saikh No AdvanceRohini Sector 22 Call Girls Delhi 9999965857 @Sabina Saikh No Advance
Rohini Sector 22 Call Girls Delhi 9999965857 @Sabina Saikh No Advance
 
Delhi Call Girls Rohini 9711199171 ☎✔👌✔ Whatsapp Hard And Sexy Vip Call
Delhi Call Girls Rohini 9711199171 ☎✔👌✔ Whatsapp Hard And Sexy Vip CallDelhi Call Girls Rohini 9711199171 ☎✔👌✔ Whatsapp Hard And Sexy Vip Call
Delhi Call Girls Rohini 9711199171 ☎✔👌✔ Whatsapp Hard And Sexy Vip Call
 
@9999965857 🫦 Sexy Desi Call Girls Laxmi Nagar 💓 High Profile Escorts Delhi 🫶
@9999965857 🫦 Sexy Desi Call Girls Laxmi Nagar 💓 High Profile Escorts Delhi 🫶@9999965857 🫦 Sexy Desi Call Girls Laxmi Nagar 💓 High Profile Escorts Delhi 🫶
@9999965857 🫦 Sexy Desi Call Girls Laxmi Nagar 💓 High Profile Escorts Delhi 🫶
 
Call Girls In Pratap Nagar Delhi 💯Call Us 🔝8264348440🔝
Call Girls In Pratap Nagar Delhi 💯Call Us 🔝8264348440🔝Call Girls In Pratap Nagar Delhi 💯Call Us 🔝8264348440🔝
Call Girls In Pratap Nagar Delhi 💯Call Us 🔝8264348440🔝
 
AWS Community DAY Albertini-Ellan Cloud Security (1).pptx
AWS Community DAY Albertini-Ellan Cloud Security (1).pptxAWS Community DAY Albertini-Ellan Cloud Security (1).pptx
AWS Community DAY Albertini-Ellan Cloud Security (1).pptx
 
DDoS In Oceania and the Pacific, presented by Dave Phelan at NZNOG 2024
DDoS In Oceania and the Pacific, presented by Dave Phelan at NZNOG 2024DDoS In Oceania and the Pacific, presented by Dave Phelan at NZNOG 2024
DDoS In Oceania and the Pacific, presented by Dave Phelan at NZNOG 2024
 
VIP 7001035870 Find & Meet Hyderabad Call Girls LB Nagar high-profile Call Girl
VIP 7001035870 Find & Meet Hyderabad Call Girls LB Nagar high-profile Call GirlVIP 7001035870 Find & Meet Hyderabad Call Girls LB Nagar high-profile Call Girl
VIP 7001035870 Find & Meet Hyderabad Call Girls LB Nagar high-profile Call Girl
 
(INDIRA) Call Girl Pune Call Now 8250077686 Pune Escorts 24x7
(INDIRA) Call Girl Pune Call Now 8250077686 Pune Escorts 24x7(INDIRA) Call Girl Pune Call Now 8250077686 Pune Escorts 24x7
(INDIRA) Call Girl Pune Call Now 8250077686 Pune Escorts 24x7
 
On Starlink, presented by Geoff Huston at NZNOG 2024
On Starlink, presented by Geoff Huston at NZNOG 2024On Starlink, presented by Geoff Huston at NZNOG 2024
On Starlink, presented by Geoff Huston at NZNOG 2024
 
GDG Cloud Southlake 32: Kyle Hettinger: Demystifying the Dark Web
GDG Cloud Southlake 32: Kyle Hettinger: Demystifying the Dark WebGDG Cloud Southlake 32: Kyle Hettinger: Demystifying the Dark Web
GDG Cloud Southlake 32: Kyle Hettinger: Demystifying the Dark Web
 
Call Now ☎ 8264348440 !! Call Girls in Sarai Rohilla Escort Service Delhi N.C.R.
Call Now ☎ 8264348440 !! Call Girls in Sarai Rohilla Escort Service Delhi N.C.R.Call Now ☎ 8264348440 !! Call Girls in Sarai Rohilla Escort Service Delhi N.C.R.
Call Now ☎ 8264348440 !! Call Girls in Sarai Rohilla Escort Service Delhi N.C.R.
 
Call Girls Ludhiana Just Call 98765-12871 Top Class Call Girl Service Available
Call Girls Ludhiana Just Call 98765-12871 Top Class Call Girl Service AvailableCall Girls Ludhiana Just Call 98765-12871 Top Class Call Girl Service Available
Call Girls Ludhiana Just Call 98765-12871 Top Class Call Girl Service Available
 

Migrating to PHP 7

  • 1. Migrating to PHP 7 John Coggeshall – International PHP Conference, 2016 Berlin, Germany @coogle, john@coggeshall.org
  • 2. Who’s This Guy? • The Author of ext/tidy • (primary) Author in (almost) 5 books on PHP going from PHP 4 to PHP 7 • Speaking at conferences for a long time !!!!! circa 2004 today
  • 3. Major Concerns when Migrating to PHP 7 • Error Handling • Variable Handling • Control Structure Changes • Removed Features / Changed Functions • Newly Deprecated Behaviors • This talk will not cover every single detail of the changes in PHP 7. That’s what Migration Documentation is for: http://php.net/manual/de/migration70.php
  • 4. Error Handling • One of the biggest breaks you may have to deal with migrating to PHP 7 will be error handling • Especially when using Custom Error Handlers • Many fatal / recoverable errors from PHP 5 have been converted to exceptions • Major Break: The callback for set_exception_handler() is not guaranteed to receive Exception objects
  • 5. Fixing Exception Handlers <?php function my_handler(Exception $e) { /* ... */ } <?php function my_handler(Throwable $e) { /* ... */ } PHP 5 PHP 7
  • 6. Other Internal Exceptions • Some internal class constructors in PHP 5 would create objects in unusable states rather than throw exceptions • In PHP 7 all class constructors throw exceptions • Notably this was a problem in some of the Reflection Classes You should always be prepared to handle an exception thrown from PHP 7 internal classes in the event something goes wrong
  • 7. Parser Errors • In PHP 5, parsing errors (for instance, from an include_once statement) would cause a fatal error • In PHP 7 parser errors throw the new ParseError exception Again, your custom error handlers and exception handlers may need updating to reflect this new behavior
  • 8. E_STRICT is Dead Situation New Behavior Indexing by a Resource E_NOTICE Abstract Static Methods No Error ”Redefining” a constructor No Error Signature mismatch during inheritance E_WARNING Same (compatible) property used in two traits No Error Accessing a static property non-statically E_NOTICE Only variables should be assigned by reference E_NOTICE Only variables should be passed by reference E_NOTICE Calling non-static methods statically E_DEPRECATED
  • 9. Indirect Variables, Properties, Methods • In PHP 5 complex indirect access to variables, properties, etc. was not consistently handled. • PHP 7 addresses these inconsistencies, at the cost of backward compatibility Typically most well-written code will not be affected by this. However, if you have complicated indirect accesses you may hit this.
  • 10. Indirect Variables, Properties, Methods Expression PHP 5 PHP 7 $$foo[‘bar’][‘baz’] ${$foo[‘bar’][‘baz’]} ($$foo)[‘bar’][‘baz’] $foo->$bar[‘baz’] $foo->{$bar[‘baz’]} ($foo->$bar)[‘baz’] $foo->$bar[‘baz’]() $foo->{$bar[‘baz’]}() ($foo->$bar)[‘baz’]() Foo::bar[‘baz’]() Foo::{$bar[‘baz’]}() (Foo::$bar)[‘baz’]() If you are using any of the expression patterns on the left column the code will need to be updated to the middle “PHP 5” column to be interpreted correctly.
  • 11. list() Mayhem • There is a lot of code out there that takes the assignment order of the list() statement for granted: <?php list($x[], $x[]) = [1, 2]; // $x = [2, 1] in PHP 5 // $x = [1, 2] in PHP 7 • This was never a good idea and you should not rely on the order in this fashion.
  • 12. list() Mayhem • Creative use of the list() statement with empty assignments will also now break <?php // Both will now break in PHP 7 list() = $array; list(,$x) = $array;
  • 13. list() Mayhem • Finally, list() can no longer be used to unpack strings. <?php list($a, $b, $c) = “abc”; // $a = “a” in PHP 5, breaks in PHP 7
  • 14. Subtle foreach() changes – Array Pointers • In PHP 5 iterating over an array using foreach() would cause the internal array pointer to move for each iteration <?php $a = [1, 2] foreach($a as &$val) { var_dump(current($a)); } // Output in PHP 5: // int(1) // int(2) // bool(false) <?php $a = [1, 2] foreach($a as &$val) { var_dump(current($a)); } // Output in PHP 7: // int(1) // int(1) // int(1)
  • 15. Subtle foreach() changes – References This subtle change may break code that modifies arrays by reference during an iteration of it <?php $a = [0]; foreach($a as &$val) { var_dump($val); $a[1] = 1; } // Output in PHP 5 // int(0) <?php $a = [0]; foreach($a as &$val) { var_dump($val); $a[1] = 1; } // Output in PHP 7 // int(0) // int(1) In PHP 5 you couldn’t add to an array, even when passing it by reference and iterate over them in the same block
  • 16. Integer handler changes • Invalid Octal literals now throw parser errors instead of being silently ignored • Bitwise shifts of integers by negative numbers now throws an ArithmeticError • Bitwise shifts that are out of range will now always be int(0) rather than being architecture-dependent
  • 17. Division By Zero • In PHP 5 Division by Zero would always cause an E_WARNING and evaluate to int(0), including attempting to do a modulus (%) by zero • In PHP 7 • X / 0 == float(INF) • 0 / 0 == float(NaN) • Attempting to do a modulus of zero now causes a DivisionByZeroError exception to be thrown
  • 18. Hexadecimals and Strings • In PHP 5 strings that evaluated to hexadecimal values could be cast to numeric values • I.e. (int)“0x123” == 291 • In PHP 7 strings are no longer directly interpretable as numeric values • I.e. (int)”0x123” == 0 • If you need to convert a string hexadecimal value to its integer equivalent you can use filter_var() with the FILTER_VALIDATE_INT and FILTER_FLAG_ALLOW_HEX options to convert it to an integer value.
  • 19. Calls from Incompatible Contexts • Static calls made to a non-static method with an incompatible context (i.e. calling a non-static method statically in a completely unrelated class) has thrown a E_DEPRECATED error since 5.6 • I.e. Class A calls a non-static method in Class B statically • In PHP 5, $this would still be defined pointing to class A • In PHP 7, $this is no longer defined
  • 20. yield is now right associative • In PHP 5 the yield construct no longer requires parentheses and has been changed to a right associative operator <?php // PHP 5 echo yield -1; // (yield) – 1; yield $foo or die // yield ($foo or die) <?php // PHP 7 echo yield -1; // yield (-1) yield $foo or die // (yield $foo) or die;
  • 21. Misc Incompatibilities • There are a number of other (smaller) incompatibilities between PHP 5 and PHP 7 worth mentioning • ASP-style tags <% %> have been removed • <script language=“php”> style tags have been removed • Assigning the result of the new statement by reference is now fatal error • Functions that have multiple parameters with the same name is now a compile error • switch statements with multiple default blocks is now a compile error • $HTTP_RAW_POST_DATA has been removed in favor of php://input • # comments in .ini files parsed by PHP are no longer supported (use semicolon) • Custom session handlers that return false result in fatal errors now
  • 22. Removed Functions • Numerous functions have been removed in PHP 7 and replaced with better equivalents where appropriate Variable Functions call_user_method() call_user_method_array() Mcrypt mcrypt_generic_end() mcrypt_ecb() mcrypt_cbc() mcrypt_cfb() mcrypt_ofb() Intl datefmt_set_timezone_id() IntlDateFormatter::setTimeZoneId() System set_magic_quotes_runtime() magic_quotes_runtime() set_socket_blocking() dl() (in PHP-FPM) = GD imagepsbbox() imagepsencodefont() imagepsextendfont() imagepsfreefont() imagepsloadfont() imagepsslantfont() imagepstext() • Removed Extensions: ereg, mssql, mysql, sybase_ct
  • 23. Removed Server APIs (SAPIs) and extensions • Numerous Server APIs (SAPIs) have been removed from PHP 7: • aolserver • apache • apache_hooks • apache2filter • caudium • continunity • isapi • milter • nsapi • phttpd • pi3web • roxen • thttpd • tux • webjames
  • 24. Deprecated Features • A number of things have been deprecated in PHP 7, which means they will now throw E_DEPRECATED errors if you happen to be using them in your code • PHP 4 style constructors • Static calls to non-static methods • Passing your own salt to the password_hash() function • capture_session_meta SSL context option • For now these errors can be suppressed (using the @ operator) but the code should be updated as necessary.
  • 25. Changes to Core Functions • When migrating from PHP 5 to PHP 7 there are a few functions that have changed behaviors worth noting • mktime() and gmmktime() no longer accept the $is_dst parameter • preg_replace() no longer supports the /e modifier and preg_replace_callback() must now be used • setlocale() no longer accepts strings for the $category parameter. The LC_* constants must be used • substr() now returns an empty string if then $string parameter is as long as the $start parameter value.
  • 26. Name Conflicts • There are a lot of new things in PHP 7 that didn’t exist in PHP 5 • New Functions • New Methods • New Classes • New Constants • New Exceptions • You should review the PHP Migration documentation for what’s been added to determine if any code you’ve written now conflicts with something internal to PHP 7 • For example, do you have an IntlChar class in your application?