SlideShare a Scribd company logo
The Why and How of moving to PHP 7.x
Join the chat
http://www.midwestphp.org/chat
Channel #everyday-php
Who am I ?
Wim Godden (@wimgtr)
Where I'm from
Where I'm from
Where I'm from
Where I'm from
Where I'm from
Where I'm from
My town
My town
Belgium – the traffic
Who am I ?
Wim Godden (@wimgtr)
Founder of Cu.be Solutions (http://cu.be)
Open Source developer since 1997
Developer of PHPCompatibility, OpenX, ...
Speaker at Open Source conferences
Why vs How
Part 1 : why upgrade ?
Bad reasons :
It's cool to have the latest version
Annoy sysadmins
Oh cool, a new toy !
Part 2 : how to upgrade ?
The nightmare of compatibility
The joy of automation
No miracles here !
Show of hands
3 / 4
5.0
5.1
5.2
5.3
5.4
5.5
5.6
6.0
7.0
7.1
7.2
7.3
7.4
8.0
The numbers
W3Techs (http://w3techs.com/technologies/details/pl-php/all/all)
Now Oct 2018 Jan 2015
PHP 4 : 0.4% 0.8% 1.8%
PHP 5 : 50.0% 87.2% 98.2%
5.0 : < 0.1% < 0.1% 0.1%
5.1 : 0.3% 0.5% 1.2%
5.2 : 6.1% 7.8% 19.2%
5.3 : 14.8% 19.7% 45.5%
5.4 : 17.7% 21.2% 26.9%
5.5 : 10.0% 15.4% 6.3%
5.6 : 51.0% 35.3% 0.5%
PHP 7 : 49.6% 12.0%
7.0 : 19.4% 66.8%
7.1 : 17.8% 31.2%
7.2 : 35.3% 2.1%
7.3 : 24.8%
7.4 : 2.7%
5.3 – 5.6 quick recap
Namespaces ()
Late static binding
Closures
Better garbage collection
Goto
Mysqlnd
Performance gain
Short array syntax
Traits
Built-in webserver
Binary notation
No more register_globals, magic_quotes_gpc and safe_mode
Generators (yield keyword)
password_hash() function
Built-in opcache
PHP 7.x – what's changed ?
New features
Performance and memory usage
Improved consistency
Lots of things removed or deprecated
New things – Scalar type + return type declarations (7.0)
New scalar types : int, float, bool and string
Return type can be specified as well
(and can be scalar type as well)
Weak and strong typing
Weak :
Default
Parameters will be coerced (PHP 5 style)
Strong/strict :
At top of file :
Strict typing is file-specific, so must be enabled in each file !
If wrong type is given, a TypeError is thrown :
Fatal error: Uncaught TypeError: Return value of testFunction() must be
of the type integer, string returned
Returning null is also invalid → if you want an int, you will get an int or an error
Null coalescing operator (??)
PHP 5 :
PHP 7 :
Can be chained :
The why and how of moving to php 7
Spaceship operator (<=>)
Compares expressions
Returns -1, 0 or 1
Examples :
Unicode codepoint escape syntax
Converts hexadecimal Unicode codepoint to UTF8 double quoted string
will output :
CSPRNG functions
Cross platform functions to generate random data
Cryptographically secure
2 functions :
random_bytes($length)
random_int($min, $max)
Deprecated in PHP 7.0
PHP 4 style constructors
Static calls to non-static methods
Error handling in PHP 7
Most fatal errors in PHP 5 → Exceptions in PHP 7
New class : Error
If your PHP 5 code has a class called Error, you will need to rename it
All Error and Exception classes now implement Throwable
Error Flow :
Error is thrown
Bubbles up through called functions/methods
At first matching catch block, code is run
No matching catch → default exception handler
No default exception handler → Fatal error
Error
ArithmeticError
DivisionByZeroError
AssertionError
ParseError
TypeError
ArgumentCountError
Exception
ClosedGeneratorException
DOMException
ErrorException
IntlException
LogicException
BadFunctionCallException
BadMethodCallException
DomainException
InvalidArgumentException
LengthException
OutOfRangeException
PharException
ReflectionException
RuntimeException
OutOfBoundsException
OverflowException
PDOException
RangeException
UnderflowException
UnexpectedValueException
SodiumException
Variable handling
PHP 7 uses abstract syntax tree (AST)
Can be detected automatically in some cases
Requires manual fixing and testing
Removed extensions
ereg
mssql
mysql
sybase_ct
mcrypt (PHP 7.1)
Other changes (1/2)
Invalid octals now throw a ParseError
PHP Parse error: Invalid numeric literal in octal.php
Negative bitshifts throw an ArithmeticError
Fatal error: Uncaught ArithmeticError: Bit shift by negative number
Division by zero throws DivisionByZeroError
Hexadecimal strings are no longer numeric
In PHP 5 : bool(true)
In PHP 7 : bool(false)
Other changes (2/2)
New reserved keywords : bool, float, int, null, string, true, false
Reserved for future use : mixed, number, object, resource, void (7.1), iterable (7.1)
However, keyword usage inside classes is less restrictive. This is now allowed :
Performance and memory usage from 5.6 to 7.0
Performance : 200 – 300% increase
How ?
Core optimizations
More direct approach
Fewer memory allocations
Smaller data structures across all data types
…
Reduced memory usage : up to 50% !
Big impact on large frameworks
Even bigger impact on codebases such as Wordpress, Drupal, ...
PHP 7.0 → 7.1 (1/2)
Nullable types
Exception on passing too few function arguments
Fatal error: Uncaught ArgumentCountError: Too few arguments to
function test(), 0 passed in %s on line %d and exactly 1
expected in %s:%d
PHP 7.0 → 7.1 (2/2)
DateTime constructor now uses microseconds
SSLv2 stream support has been dropped
PHP 7.1 → 7.2
object type is available call parameter type and return type of any objects
Sodium extension added : modern cryptographic library
TLS version used is now 1.0, 1.1 or 1.2 (instead of 1.0 only)
create_function() is deprecated
__autoload() is deprecated
each() is deprecated
PHP 7.2 → 7.3 (1/2)
Flexible heredoc and nowdoc
Trailing commas are allowed in function calls
PHP 7.2 → 7.3 (2/2)
array_key_first() and array_key_last()
Argon2 hashing algorithm
continue in switch statement generates a warning
Mysqli and PDO_Mysql now return fractional seconds for datetime, time and
timestamp (!)
Constants can no longer be defined as case-insensitive
is_countable()
PHP 7.3 → 7.4 (1/2)
Typed properties
→ Will be checked on read/write
Null Coalesce Assignment operator :
FFI (Foreign Function Interface) :
Allows PHP to talk directly to C libraries
Experimental
Preloading
Like Opcache on steroids
Will preload all files and opcache them
Requires restart of web server / PHP-FPM to reload any changed files
PHP 7.3 → 7.4 (2/2)
Operator precedence deprecation :
In PHP 7.4 :
Deprecated: The behavior of unparenthesized expressions containing both '.' and '+'/'-' will
change in PHP 8: '+'/'-' will take a higher precedence in test.php on line 4
Deprecated curly brace syntax for accessing array elements :
Output : 3 !!!
So...
Should you upgrade today ?
Postponing upgrades - End-Of-Life
In the past : we'll see
Now : 2 years after initial release
Critical security patches : 1 extra year (but no regular bugfixes)
In practice
7.1 was released Dec 2016 → already EOL (Nov 30 2019)
7.2 was released Nov 2017 → already EOL (Nov 2019)
7.3 was released Dec 2018 → EOL Dec 2020
7.4 was released Nov 28 → EOL Nov 2021
If you’re on PHP 7.0 - 7.2 → start upgrading !
Postponing upgrades
Security
Performance
Framework support
Symfony 5 : PHP 7.2.5+
Zend Framework 3 : PHP 5.6+
Laravel 6 : PHP 7.2+
Developer motivation
Upgrade paths
1 upgrade every 5 years
Knowledge of upgrade steps will be forgotten
Documentation is not very useful (for example : SysvInit → Systemd)
Massive task to upgrade all apps, all environments, all servers
Upgrade every release
Upgrade steps can be automated
Can be integrated with continuous integration and continuous deployment
Documentation is in the automation flow
So you want to upgrade...
Option 1 : run your unit tests
Option 2 : visit each page (good luck !) + check error_log
Or : record visits, then replay log on test environment
Or : proxy requests to 2 environments
Option 3 : automated static analysis
Back in 2010...
PHP Architect @ Belgian Railways
8 years of legacy code (4.x and 5.x)
40+ different developers
40+ projects
Challenge :
migrate all projects from
PHP 5.1.x (on Solaris)
to
PHP 5.3.x (on Linux)
The idea
Automate it
How ? → Use the CI environment
Which tool ? → PHP_CodeSniffer
PHP_CodeSniffer
Originally PEAR package (pear install PHP_CodeSniffer)
Also on Composer now
Detects coding standard violations
Supports multiple standards
Static analysis tool
→ Runs without executing code
→ Splits code in tokens
Ex. : T_OPEN_CURLY_BRACKET
T_FALSE
T_SEMICOLON
→ Parses each file separately
PHP_CodeSniffer
Let's see what it looks like
PHP_CodeSniffer options
-i Show available standards
-p Show progress
-s Show real error/warning sniff names
-n Ignore warnings
-v Verbose
--parallel=x (since PHP_CodeSniffer 3)
PHPCompatibility
PHP_CodeSniffer standard
Only purpose : find compatibility issues
Detects :
Deprecated functions
Deprecated extensions
Deprecated php.ini settings and ini_set() calls
Prohibited function names, class names, …
…
Works for PHP 5.0 5.3 and above (5.4 for PHP_CodeSniffer 3 support)
PHPCompatibility – making it work - Composer
In require-dev : phpcompatibility/php-compatibility
If PHPCompatibility is the only PHP CodeSniffer standard :
"scripts": {
"post-install-cmd": ""vendor/bin/phpcs" --config-set installed_paths vendor/wimg/php-compatibility/PHPCompatibility",
"post-update-cmd" : ""vendor/bin/phpcs" --config-set installed_paths vendor/wimg/php-compatibility/PHPCompatibility"
}
Otherwise use one of these :
DealerDirect/phpcodesniffer-composer-installer
higidi/composer-phpcodesniffer-standards-plugin
PHPCompatibility – making it work - Github
Download PHP CodeSniffer
Download from http://github.com/phpcompatibility/PHPCompatibility
Run phpcs --config-set installed_paths /path/to/PHPCompatibility
PHPCompatibility – making it work – testing and running
Check if coding standard is available :
phpcs -i
Should output something similar to :
The installed coding standards are MySource, PEAR,
PHPCompatibility, PHPCS, PSR1, PSR2, Squiz and Zend
To run :
phpcs --standard=PHPCompatibility /path/of/your/code
Important notes
Large directories → can be slow !
Use --extensions=php
No point scanning .js files
Test PHP x.x compatibility → needs PHP x.x on the system
Static analysis
Doesn't actually run the code
Can not detect every single incompatibility → some things only happen on runtime
Provides filename and line number
Checking for specific versions
Default : latest PHP version
Check for single version :
phpcs --standard=PHPCompatibility --runtime-set testVersion 7.0 srcdir
Check for multiple specific versions :
phpcs --standard=PHPCompatibility --runtime-set testVersion 7.0-7.1 srcdir
Check for minimum version :
phpcs --standard=PHPCompatibility --runtime-set testVersion 7.0- srcdir
Checking for older version :
phpcs --standard=PHPCompatibility --runtime-set testVersion 5.0 srcdir
Extra rulesets
Other tools
For Wordpress : PHP Compatibility Checker (uses PHPCompatibility)
Other tools
For Wordpress : PHP Compatibility Checker (uses PHPCompatibility)
PhpStorm 10+ : PHP 7 Compatibility Inspection
sstalle/php7cc : similar functionality, slightly less up-to-date
phan/phan : general static analyzer, compatibility checks are mostly useful for type
checking
adamculp/php-compatibility-check : docker image that uses PHPCompatibility,
php7cc and phan
Conclusion
No 100% detection
But : 95% automation = lots of time saved !
First : PHPCompatibility on local machine
Then : use your CI environment
Start upgrading !
Big thanks to...
Juliette Reinders Folmer
Has been the main contributor (95%+ of all commits) in last 3 years
PHP_CodeSniffer wizard
Questions ?
Questions ?
Thanks !

More Related Content

PDF
The why and how of moving to php 8
ODP
The why and how of moving to php 7.x
ODP
The why and how of moving to php 7.x
PDF
Static Analysis of PHP Code – IPC Berlin 2016
PDF
Test Driven Development of A Static Code Analyzer
PDF
50 shades of PHP
PPT
Python - Introduction
ODP
An Introduction to PC-Lint
The why and how of moving to php 8
The why and how of moving to php 7.x
The why and how of moving to php 7.x
Static Analysis of PHP Code – IPC Berlin 2016
Test Driven Development of A Static Code Analyzer
50 shades of PHP
Python - Introduction
An Introduction to PC-Lint

What's hot (20)

PDF
Static Code Analysis and Cppcheck
PDF
Doing the Impossible
PPTX
Learn python – for beginners
PDF
Modern Python Testing
PDF
Boo Manifesto
PDF
Joomla Code Quality Control and Automation Testing
PPT
Perl Modules
PPT
What do you mean it needs to be Java based? How jython saved the day.
PDF
(1) c sharp introduction_basics_dot_net
PPT
Packer Genetics: The selfish code
PDF
Python Testing Fundamentals
PDF
ShaREing Is Caring
PDF
Static analysis for perl
PPTX
Python basics
PPTX
JDD 2016 - Sebastian Malaca - You Dont Need Unit Tests
PPT
Php5 vs php7
PPTX
Quality assurance of large c++ projects
PDF
Checking the Code of LDAP-Server ReOpenLDAP on Our Readers' Request
PPT
Communication between Java and Python
PDF
Variety of automated tests
Static Code Analysis and Cppcheck
Doing the Impossible
Learn python – for beginners
Modern Python Testing
Boo Manifesto
Joomla Code Quality Control and Automation Testing
Perl Modules
What do you mean it needs to be Java based? How jython saved the day.
(1) c sharp introduction_basics_dot_net
Packer Genetics: The selfish code
Python Testing Fundamentals
ShaREing Is Caring
Static analysis for perl
Python basics
JDD 2016 - Sebastian Malaca - You Dont Need Unit Tests
Php5 vs php7
Quality assurance of large c++ projects
Checking the Code of LDAP-Server ReOpenLDAP on Our Readers' Request
Communication between Java and Python
Variety of automated tests
Ad

Similar to The why and how of moving to php 7 (20)

ODP
Is your code ready for PHP 7 ?
PDF
What To Expect From PHP7
ODP
The why and how of moving to PHP 5.5/5.6
ODP
The why and how of moving to php 5.4
PPT
Php manish
PPTX
Listen and look at your PHP code
DOCX
Guidelines php 8 gig
PPTX
Listen afup 2010
PDF
PDF
How Symfony Changed My Life
PDF
How Symfony changed my life (#SfPot, Paris, 19th November 2015)
PPT
Php training100%placement-in-mumbai
PPTX
PHP ITCS 323
PDF
The new features of PHP 7 - Enrico Zimuel - Codemotion Milan 2016
PDF
The new features of PHP 7
ODP
Incredible Machine with Pipelines and Generators
PPTX
Php 5.6 vs Php 7 performance comparison
PPS
Simplify your professional web development with symfony
PDF
PHP 7X New Features
PDF
Last train to php 7
Is your code ready for PHP 7 ?
What To Expect From PHP7
The why and how of moving to PHP 5.5/5.6
The why and how of moving to php 5.4
Php manish
Listen and look at your PHP code
Guidelines php 8 gig
Listen afup 2010
How Symfony Changed My Life
How Symfony changed my life (#SfPot, Paris, 19th November 2015)
Php training100%placement-in-mumbai
PHP ITCS 323
The new features of PHP 7 - Enrico Zimuel - Codemotion Milan 2016
The new features of PHP 7
Incredible Machine with Pipelines and Generators
Php 5.6 vs Php 7 performance comparison
Simplify your professional web development with symfony
PHP 7X New Features
Last train to php 7
Ad

More from Wim Godden (20)

PDF
Beyond php - it's not (just) about the code
PDF
Bringing bright ideas to life
PDF
My app is secure... I think
PDF
My app is secure... I think
PDF
Building interactivity with websockets
PDF
Bringing bright ideas to life
ODP
Your app lives on the network - networking for web developers
ODP
Beyond php - it's not (just) about the code
ODP
My app is secure... I think
ODP
Building interactivity with websockets
ODP
Your app lives on the network - networking for web developers
ODP
My app is secure... I think
ODP
My app is secure... I think
ODP
The promise of asynchronous php
ODP
My app is secure... I think
ODP
My app is secure... I think
ODP
Practical git for developers
ODP
Beyond php - it's not (just) about the code
ODP
My app is secure... I think
ODP
My app is secure... I think
Beyond php - it's not (just) about the code
Bringing bright ideas to life
My app is secure... I think
My app is secure... I think
Building interactivity with websockets
Bringing bright ideas to life
Your app lives on the network - networking for web developers
Beyond php - it's not (just) about the code
My app is secure... I think
Building interactivity with websockets
Your app lives on the network - networking for web developers
My app is secure... I think
My app is secure... I think
The promise of asynchronous php
My app is secure... I think
My app is secure... I think
Practical git for developers
Beyond php - it's not (just) about the code
My app is secure... I think
My app is secure... I think

Recently uploaded (20)

PDF
Agricultural_Statistics_at_a_Glance_2022_0.pdf
PPTX
Digital-Transformation-Roadmap-for-Companies.pptx
PDF
Network Security Unit 5.pdf for BCA BBA.
PDF
Per capita expenditure prediction using model stacking based on satellite ima...
PDF
Build a system with the filesystem maintained by OSTree @ COSCUP 2025
PDF
Blue Purple Modern Animated Computer Science Presentation.pdf.pdf
PDF
Approach and Philosophy of On baking technology
PDF
Diabetes mellitus diagnosis method based random forest with bat algorithm
PDF
Optimiser vos workloads AI/ML sur Amazon EC2 et AWS Graviton
PDF
cuic standard and advanced reporting.pdf
PDF
Spectral efficient network and resource selection model in 5G networks
PDF
Architecting across the Boundaries of two Complex Domains - Healthcare & Tech...
PPTX
Understanding_Digital_Forensics_Presentation.pptx
PDF
How UI/UX Design Impacts User Retention in Mobile Apps.pdf
PDF
Building Integrated photovoltaic BIPV_UPV.pdf
PPTX
KOM of Painting work and Equipment Insulation REV00 update 25-dec.pptx
PDF
Chapter 3 Spatial Domain Image Processing.pdf
PDF
Dropbox Q2 2025 Financial Results & Investor Presentation
PDF
The Rise and Fall of 3GPP – Time for a Sabbatical?
PPTX
20250228 LYD VKU AI Blended-Learning.pptx
Agricultural_Statistics_at_a_Glance_2022_0.pdf
Digital-Transformation-Roadmap-for-Companies.pptx
Network Security Unit 5.pdf for BCA BBA.
Per capita expenditure prediction using model stacking based on satellite ima...
Build a system with the filesystem maintained by OSTree @ COSCUP 2025
Blue Purple Modern Animated Computer Science Presentation.pdf.pdf
Approach and Philosophy of On baking technology
Diabetes mellitus diagnosis method based random forest with bat algorithm
Optimiser vos workloads AI/ML sur Amazon EC2 et AWS Graviton
cuic standard and advanced reporting.pdf
Spectral efficient network and resource selection model in 5G networks
Architecting across the Boundaries of two Complex Domains - Healthcare & Tech...
Understanding_Digital_Forensics_Presentation.pptx
How UI/UX Design Impacts User Retention in Mobile Apps.pdf
Building Integrated photovoltaic BIPV_UPV.pdf
KOM of Painting work and Equipment Insulation REV00 update 25-dec.pptx
Chapter 3 Spatial Domain Image Processing.pdf
Dropbox Q2 2025 Financial Results & Investor Presentation
The Rise and Fall of 3GPP – Time for a Sabbatical?
20250228 LYD VKU AI Blended-Learning.pptx

The why and how of moving to php 7

  • 1. The Why and How of moving to PHP 7.x
  • 3. Who am I ? Wim Godden (@wimgtr)
  • 12. Belgium – the traffic
  • 13. Who am I ? Wim Godden (@wimgtr) Founder of Cu.be Solutions (http://cu.be) Open Source developer since 1997 Developer of PHPCompatibility, OpenX, ... Speaker at Open Source conferences
  • 14. Why vs How Part 1 : why upgrade ? Bad reasons : It's cool to have the latest version Annoy sysadmins Oh cool, a new toy ! Part 2 : how to upgrade ? The nightmare of compatibility The joy of automation No miracles here !
  • 15. Show of hands 3 / 4 5.0 5.1 5.2 5.3 5.4 5.5 5.6 6.0 7.0 7.1 7.2 7.3 7.4 8.0
  • 16. The numbers W3Techs (http://w3techs.com/technologies/details/pl-php/all/all) Now Oct 2018 Jan 2015 PHP 4 : 0.4% 0.8% 1.8% PHP 5 : 50.0% 87.2% 98.2% 5.0 : < 0.1% < 0.1% 0.1% 5.1 : 0.3% 0.5% 1.2% 5.2 : 6.1% 7.8% 19.2% 5.3 : 14.8% 19.7% 45.5% 5.4 : 17.7% 21.2% 26.9% 5.5 : 10.0% 15.4% 6.3% 5.6 : 51.0% 35.3% 0.5% PHP 7 : 49.6% 12.0% 7.0 : 19.4% 66.8% 7.1 : 17.8% 31.2% 7.2 : 35.3% 2.1% 7.3 : 24.8% 7.4 : 2.7%
  • 17. 5.3 – 5.6 quick recap Namespaces () Late static binding Closures Better garbage collection Goto Mysqlnd Performance gain Short array syntax Traits Built-in webserver Binary notation No more register_globals, magic_quotes_gpc and safe_mode Generators (yield keyword) password_hash() function Built-in opcache
  • 18. PHP 7.x – what's changed ? New features Performance and memory usage Improved consistency Lots of things removed or deprecated
  • 19. New things – Scalar type + return type declarations (7.0) New scalar types : int, float, bool and string Return type can be specified as well (and can be scalar type as well)
  • 20. Weak and strong typing Weak : Default Parameters will be coerced (PHP 5 style) Strong/strict : At top of file : Strict typing is file-specific, so must be enabled in each file ! If wrong type is given, a TypeError is thrown : Fatal error: Uncaught TypeError: Return value of testFunction() must be of the type integer, string returned Returning null is also invalid → if you want an int, you will get an int or an error
  • 21. Null coalescing operator (??) PHP 5 : PHP 7 : Can be chained :
  • 23. Spaceship operator (<=>) Compares expressions Returns -1, 0 or 1 Examples :
  • 24. Unicode codepoint escape syntax Converts hexadecimal Unicode codepoint to UTF8 double quoted string will output :
  • 25. CSPRNG functions Cross platform functions to generate random data Cryptographically secure 2 functions : random_bytes($length) random_int($min, $max)
  • 26. Deprecated in PHP 7.0 PHP 4 style constructors Static calls to non-static methods
  • 27. Error handling in PHP 7 Most fatal errors in PHP 5 → Exceptions in PHP 7 New class : Error If your PHP 5 code has a class called Error, you will need to rename it All Error and Exception classes now implement Throwable Error Flow : Error is thrown Bubbles up through called functions/methods At first matching catch block, code is run No matching catch → default exception handler No default exception handler → Fatal error
  • 29. Variable handling PHP 7 uses abstract syntax tree (AST) Can be detected automatically in some cases Requires manual fixing and testing
  • 31. Other changes (1/2) Invalid octals now throw a ParseError PHP Parse error: Invalid numeric literal in octal.php Negative bitshifts throw an ArithmeticError Fatal error: Uncaught ArithmeticError: Bit shift by negative number Division by zero throws DivisionByZeroError Hexadecimal strings are no longer numeric In PHP 5 : bool(true) In PHP 7 : bool(false)
  • 32. Other changes (2/2) New reserved keywords : bool, float, int, null, string, true, false Reserved for future use : mixed, number, object, resource, void (7.1), iterable (7.1) However, keyword usage inside classes is less restrictive. This is now allowed :
  • 33. Performance and memory usage from 5.6 to 7.0 Performance : 200 – 300% increase How ? Core optimizations More direct approach Fewer memory allocations Smaller data structures across all data types … Reduced memory usage : up to 50% ! Big impact on large frameworks Even bigger impact on codebases such as Wordpress, Drupal, ...
  • 34. PHP 7.0 → 7.1 (1/2) Nullable types Exception on passing too few function arguments Fatal error: Uncaught ArgumentCountError: Too few arguments to function test(), 0 passed in %s on line %d and exactly 1 expected in %s:%d
  • 35. PHP 7.0 → 7.1 (2/2) DateTime constructor now uses microseconds SSLv2 stream support has been dropped
  • 36. PHP 7.1 → 7.2 object type is available call parameter type and return type of any objects Sodium extension added : modern cryptographic library TLS version used is now 1.0, 1.1 or 1.2 (instead of 1.0 only) create_function() is deprecated __autoload() is deprecated each() is deprecated
  • 37. PHP 7.2 → 7.3 (1/2) Flexible heredoc and nowdoc Trailing commas are allowed in function calls
  • 38. PHP 7.2 → 7.3 (2/2) array_key_first() and array_key_last() Argon2 hashing algorithm continue in switch statement generates a warning Mysqli and PDO_Mysql now return fractional seconds for datetime, time and timestamp (!) Constants can no longer be defined as case-insensitive is_countable()
  • 39. PHP 7.3 → 7.4 (1/2) Typed properties → Will be checked on read/write Null Coalesce Assignment operator : FFI (Foreign Function Interface) : Allows PHP to talk directly to C libraries Experimental Preloading Like Opcache on steroids Will preload all files and opcache them Requires restart of web server / PHP-FPM to reload any changed files
  • 40. PHP 7.3 → 7.4 (2/2) Operator precedence deprecation : In PHP 7.4 : Deprecated: The behavior of unparenthesized expressions containing both '.' and '+'/'-' will change in PHP 8: '+'/'-' will take a higher precedence in test.php on line 4 Deprecated curly brace syntax for accessing array elements : Output : 3 !!!
  • 42. Postponing upgrades - End-Of-Life In the past : we'll see Now : 2 years after initial release Critical security patches : 1 extra year (but no regular bugfixes) In practice 7.1 was released Dec 2016 → already EOL (Nov 30 2019) 7.2 was released Nov 2017 → already EOL (Nov 2019) 7.3 was released Dec 2018 → EOL Dec 2020 7.4 was released Nov 28 → EOL Nov 2021 If you’re on PHP 7.0 - 7.2 → start upgrading !
  • 43. Postponing upgrades Security Performance Framework support Symfony 5 : PHP 7.2.5+ Zend Framework 3 : PHP 5.6+ Laravel 6 : PHP 7.2+ Developer motivation
  • 44. Upgrade paths 1 upgrade every 5 years Knowledge of upgrade steps will be forgotten Documentation is not very useful (for example : SysvInit → Systemd) Massive task to upgrade all apps, all environments, all servers Upgrade every release Upgrade steps can be automated Can be integrated with continuous integration and continuous deployment Documentation is in the automation flow
  • 45. So you want to upgrade... Option 1 : run your unit tests Option 2 : visit each page (good luck !) + check error_log Or : record visits, then replay log on test environment Or : proxy requests to 2 environments Option 3 : automated static analysis
  • 46. Back in 2010... PHP Architect @ Belgian Railways 8 years of legacy code (4.x and 5.x) 40+ different developers 40+ projects Challenge : migrate all projects from PHP 5.1.x (on Solaris) to PHP 5.3.x (on Linux)
  • 47. The idea Automate it How ? → Use the CI environment Which tool ? → PHP_CodeSniffer
  • 48. PHP_CodeSniffer Originally PEAR package (pear install PHP_CodeSniffer) Also on Composer now Detects coding standard violations Supports multiple standards Static analysis tool → Runs without executing code → Splits code in tokens Ex. : T_OPEN_CURLY_BRACKET T_FALSE T_SEMICOLON → Parses each file separately
  • 50. PHP_CodeSniffer options -i Show available standards -p Show progress -s Show real error/warning sniff names -n Ignore warnings -v Verbose --parallel=x (since PHP_CodeSniffer 3)
  • 51. PHPCompatibility PHP_CodeSniffer standard Only purpose : find compatibility issues Detects : Deprecated functions Deprecated extensions Deprecated php.ini settings and ini_set() calls Prohibited function names, class names, … … Works for PHP 5.0 5.3 and above (5.4 for PHP_CodeSniffer 3 support)
  • 52. PHPCompatibility – making it work - Composer In require-dev : phpcompatibility/php-compatibility If PHPCompatibility is the only PHP CodeSniffer standard : "scripts": { "post-install-cmd": ""vendor/bin/phpcs" --config-set installed_paths vendor/wimg/php-compatibility/PHPCompatibility", "post-update-cmd" : ""vendor/bin/phpcs" --config-set installed_paths vendor/wimg/php-compatibility/PHPCompatibility" } Otherwise use one of these : DealerDirect/phpcodesniffer-composer-installer higidi/composer-phpcodesniffer-standards-plugin
  • 53. PHPCompatibility – making it work - Github Download PHP CodeSniffer Download from http://github.com/phpcompatibility/PHPCompatibility Run phpcs --config-set installed_paths /path/to/PHPCompatibility
  • 54. PHPCompatibility – making it work – testing and running Check if coding standard is available : phpcs -i Should output something similar to : The installed coding standards are MySource, PEAR, PHPCompatibility, PHPCS, PSR1, PSR2, Squiz and Zend To run : phpcs --standard=PHPCompatibility /path/of/your/code
  • 55. Important notes Large directories → can be slow ! Use --extensions=php No point scanning .js files Test PHP x.x compatibility → needs PHP x.x on the system Static analysis Doesn't actually run the code Can not detect every single incompatibility → some things only happen on runtime Provides filename and line number
  • 56. Checking for specific versions Default : latest PHP version Check for single version : phpcs --standard=PHPCompatibility --runtime-set testVersion 7.0 srcdir Check for multiple specific versions : phpcs --standard=PHPCompatibility --runtime-set testVersion 7.0-7.1 srcdir Check for minimum version : phpcs --standard=PHPCompatibility --runtime-set testVersion 7.0- srcdir Checking for older version : phpcs --standard=PHPCompatibility --runtime-set testVersion 5.0 srcdir
  • 58. Other tools For Wordpress : PHP Compatibility Checker (uses PHPCompatibility)
  • 59. Other tools For Wordpress : PHP Compatibility Checker (uses PHPCompatibility) PhpStorm 10+ : PHP 7 Compatibility Inspection sstalle/php7cc : similar functionality, slightly less up-to-date phan/phan : general static analyzer, compatibility checks are mostly useful for type checking adamculp/php-compatibility-check : docker image that uses PHPCompatibility, php7cc and phan
  • 60. Conclusion No 100% detection But : 95% automation = lots of time saved ! First : PHPCompatibility on local machine Then : use your CI environment Start upgrading !
  • 61. Big thanks to... Juliette Reinders Folmer Has been the main contributor (95%+ of all commits) in last 3 years PHP_CodeSniffer wizard