SlideShare a Scribd company logo
1 of 41
Download to read offline
Preparing for the next 
PHP version
Towards PHP 5.5 and 5.6 
• Changing version is often a big challenge 
• Backward incompatibilities 
• New features 
• How to spot them ?
Speaker 
• Damien Seguy 
• CTO at exakat 
• Phather of the plush toy 
elePHPant 
• Will talk on automated 
code audit later
PHP linting 
• command line : php -l filename.php 
• Will only parse the code, 
• not execution 
• Will spot compilation problems
PHP lint will find 
• Short array syntax 
• Function subscripting 
• break/continue with variables 
• Rare other situations 
• Code that won’t compile anyway
Where else code will break? 
• PHP running has 3 stages 
• parsed 
• compiled 
• executed 
Checked with lint 
Checked code review 
Checked with data and UT
What will change? 
• Removed features 
• Deprecated features 
• Changed features 
• New features
Deprecated features 
• PHP 5.6 
• $HTTP_RAW_POST_DATA 
5.6 
• Call From Incompatible Context 
• iconv and mbstring directives go to default_charset 
• PHP 5.5 
• /e in preg_replace 
• ext/mysql 
5.5 
• mcrypt arguments
Deprecated features 
• $HTTP_RAW_POST_DATA 
• Replace it by php://input 
• php://input is now reusable 
• ext/mysql 
• Look for mysql_* functions 
• Probably in Db/Adapter 
5.6 
5.5
Search is your friend 
• Grep, or IDE’s search function will help you 
• Look for mysql_* 
• $HTTP_RAW_POST_DATA
Error_level to E_STRICT 
Deprecated: The mysql extension is 
deprecated and will be removed in 
the future: use mysqli or PDO 
instead in /path/to/filename.php on 
line 11
/e and charset directives 
• preg_replace(‘/ /e’, ‘evaled code’, 
$haystack) 
• replaced preg_replace_callback(‘/ /‘, 
closure, $haystack) 
• in php.ini, check for mbstring, iconv and 
default_charset 
5.5 
5.6
Where to look for 
• preg_replace 
• Search for preg_replace function calls 
• defaut_charset 
• Search for ini_set, ini_get, ini_get_all, 
ini_restore, get_cfg_var 
• Seach in php.ini, .htaccess
Incompatible context 
$ php53 test.php 
Notice: Undefined variable: this in test.php on line 3 
A 
<?php 
class A { 
function f() { echo get_class($this); } 
} 
A::f(); 
?> 
5.6 
$ php56 test.php 
Strict Standards: Non-static method A::f() should not be called 
statically in /Users/famille/Desktop/test.php on line 6 
Notice: Undefined variable: this in test.php on line 3 
A
Search for situations 
• Search for :: operator 
• Get the class 
• then the method 
• then the static keyword 
• Needs a automated auditing tool 
• Code sniffer, IDE
Strict Standards: Non-static method 
A::f() should not be called 
statically in test.php on line 6
Changed behavior 
• json_decode is stricter 
• it was more tolerant before with TRUE or False values 
• gmp resources are object 
• and not resources 
• search for is_resource() 
• mcrypt requires valid keys and vectors 
• check correct size and vector presence 
• pack and unpack 
• More compatible with Perl 
• Z and a format code must be checked 
5.6 
5.5
Added structures 
• PHP adds 
• constants 
• functions 
• extensions 
• traits 
• interfaces
Added structures 
Functions Classes Constants 
5.3 25 18 80 
5.4 0 9 78 
5.5 113 9 37 
5.6 19 0 24 
Total 157 36 219
New features 
• Fixing 
• Modernization 
• New feature
Fixing
empty() upgrade 
• No need 
anymore to 
expressions in a 
variable for 
empty()! 
function myFunction() { 
return -2 ; 
} 
if (empty(myFunction() + 2)) { 
echo "This means 0!n"; 
} 
Fatal error: Can't use function return value in write context in test.php on line 6 
5.5
SELF::const != self::const 
<?php 
class object { 
const x = 1; 
function x() { print SELF::x."n"; } 
} 
$object = new object(); 
$object->x(); 
?> 
Fatal error: Class 'SELF' not found in test.php on line 6 
5.5
Modernization
Dereferencing 
• Direct access to 
element in a string 
or an array. 
<?php 
/// Function dereferencing 
echo str_split("123", 1 )[2]; 
echo "n"; 
/// Array dereferencing 
echo [5, 5, 3][0]; 
echo "n"; 
/// String dereferencing 
echo 'PHP'[0]; 
echo "n"; 
5.5 ?>
Power operator 
• Replaces pow() 
• Be aware of precedence 
echo pow(2, 3); 
$a=2; 
$a **= 3; 
$a = 2 ** 3; 
5.6
… Variadic 
• replaces 
func_get_args() 
• Easier to read 
function array_power($pow, ...$integers) { 
foreach($integers as $i) { 
print "$i ^ $pow = ". ($i ** $pow)."n"; 
} 
} 
array_power(3, 1, 2, 3, 4, 5); 
1 ^ 3 = 1 
2 ^ 3 = 8 
3 ^ 3 = 27 
4 ^ 3 = 64 
5 ^ 3 = 125 
5.6
Variadic … 
• replaces 
call_user_func_array 
• Easier to read 
• Works on functions 
• Works with typehint 
• Doesn’t work with 
references 
function array_power($pow, ...$integers) { 
foreach($integers as $i) { 
print "$i ^ $pow = ". ($i ** $pow)."n"; 
} 
} 
array_power(3, ...range(1, 5)); 
array_power(3, ...[1, 2, 3, 4, 5]); 
array_power(3, ...[1, 2, 3], ...[4, 5]); 
1 ^ 3 = 1 
2 ^ 3 = 8 
3 ^ 3 = 27 
4 ^ 3 = 64 
5 ^ 3 = 125
Generators 
function factors($limit) { 
$r = array(2); 
for ($i = 3; $i <= $limit; $i += 2) { 
$r[] = $i; 
} 
return $r; 
} 
$prime = 135; 
foreach (factors(sqrt($prime)) as $n) { 
echo "$n ". ($prime % $n ? ' not ' : '') . " factor} 
• $step big => huge 
memory usage 
5.5
Generators 
• New yield keyword 
• Save memory from 
n down to 1 value 
• Good for long or 
infinite loops 
• Search for range(), 
for() or loops 
function factors($limit) { 
yield 2; 
for ($i = 3; $i <= $limit; $i += 2) { 
yield $i; 
} 
} 
$prime = 135; 
foreach (factors(sqrt($prime)) as $n) { 
echo "$n ". ($prime % $n ? ' not ' : '') . " factor}
function x() { 
$r = new resource(); 
Finally try { 
$result = $r->do(); 
} 
catch (NetworkException $e) { 
unset ($r); 
throw $e; 
} 
catch (UnexpectedException $e) { 
unset ($r); 
throw $e; 
} 
catch (DaylightSavingException $e) { 
unset ($r); 
throw $e; 
} 
unset ($r); 
return $result; 
} 
• Clean up after 
exception 
• What if 
return in try? 
• Move cleaning 
to 
__destruct()? 
5.5
Finally 
• Clean up after 
exception or 
not 
• Clean up even 
when return 
too early 
function x() { 
$r = new resource(); 
try { 
$result = $r->do(); 
} 
catch (NetworkException $e) { 
throw $e; 
} 
catch (UnexpectedException $e) { 
throw $e; 
} 
catch (DaylightSavingException $e) { 
// just ignore this one 
} finally { 
unset ($r) ; 
} 
return $result; 
}
Really new
Class name resolution 
<?php 
namespace NameSpace; 
class ClassName {} 
echo ClassName::class; 
echo "n"; 
?> 
• Get the full name of 
a class with ::class 
5.5
class somePasswordSa_fe {_ debugInfo() 
private $user; 
private $password; 
public function __construct($user, $password) { 
$this->user = $user; 
$this->password = $password; 
} 
public function __debugInfo() { 
return [ 
'user' => $this->password, 
'password' => '**********', 
]; 
} 
} 
print_r(new somePasswordSafe('root', 'secret')); 
somePasswordSafe Object 
( 
[user] => secret 
[password] => ********** 
) 
5.6
use const / functions 
namespace NameSpace { 
const FOO = 42; 
function f() { echo __FUNCTION__."n"; } 
} 
namespace { 
use const NameSpaceFOO; 
use function NameSpacef; 
echo FOO."n"; 
f(); 
} 
• Importing constants 
or functions from 
another namespace 
• Keep things 
separated 
• Avoid polluting 
global namespace 
• Avoid static only 
classes 
5.6
Constant scalar expressions 
class Version { 
const MAJOR = 2; 
const MIDDLE = ONE; 
const MINOR = 1; 
const FULL = Version::MAJOR.'.'.Version::MIDDLE.'.'.Version::MINOR.'-'.PHP_VERSION; 
const SHORT = Version::MAJOR.'.'.Version::MIDDLE; 
const COMPACT = Version::MAJOR.Version::MIDDLE.Version::MINOR; 
public function f($a = (MAJOR == 2) ? 3 : Version::MINOR ** 3) { 
return $a; 
} 
} 
• Code automation 
• Won’t accept functioncalls 
• Keep it simple 
5.6
Foreach supports list 
• And any type 
<?php 
of keys 
• Good with 
Iterator 
classes 
• Not possible 
with Arrays 
class object implements Iterator { 
/.../ 
function key() { return array(1,2); } 
function current() { return 3; } 
/.../ 
} 
$object = new object(); 
foreach($object as list($a, $b) = $c) { 
print "$a + $b + $c = ".($a + $b + $c)."n"; 
} 
?> 
5.5
Context changes 
• PHP 5.6 
• Windows XP and 2003 dropped 
• Support for Zend Optimiser 
• PHP 5.5 
• phpdbg 
• Large File Upload 5.5 
5.6
www.slideshare 
.net/dseguy 
damien.seguy@gmail.com

More Related Content

What's hot

SPL: The Missing Link in Development
SPL: The Missing Link in DevelopmentSPL: The Missing Link in Development
SPL: The Missing Link in Developmentjsmith92
 
PHP Tips for certification - OdW13
PHP Tips for certification - OdW13PHP Tips for certification - OdW13
PHP Tips for certification - OdW13julien pauli
 
PHP Enums - PHPCon Japan 2021
PHP Enums - PHPCon Japan 2021PHP Enums - PHPCon Japan 2021
PHP Enums - PHPCon Japan 2021Ayesh Karunaratne
 
Building Testable PHP Applications
Building Testable PHP ApplicationsBuilding Testable PHP Applications
Building Testable PHP Applicationschartjes
 
Just-In-Time Compiler in PHP 8
Just-In-Time Compiler in PHP 8Just-In-Time Compiler in PHP 8
Just-In-Time Compiler in PHP 8Nikita Popov
 
php 2 Function creating, calling, PHP built-in function
php 2 Function creating, calling,PHP built-in functionphp 2 Function creating, calling,PHP built-in function
php 2 Function creating, calling, PHP built-in functiontumetr1
 
What's new in PHP 8.0?
What's new in PHP 8.0?What's new in PHP 8.0?
What's new in PHP 8.0?Nikita Popov
 
Arrays &amp; functions in php
Arrays &amp; functions in phpArrays &amp; functions in php
Arrays &amp; functions in phpAshish Chamoli
 
Static Optimization of PHP bytecode (PHPSC 2017)
Static Optimization of PHP bytecode (PHPSC 2017)Static Optimization of PHP bytecode (PHPSC 2017)
Static Optimization of PHP bytecode (PHPSC 2017)Nikita Popov
 
Perl.Hacks.On.Vim
Perl.Hacks.On.VimPerl.Hacks.On.Vim
Perl.Hacks.On.VimLin Yo-An
 
A Functional Guide to Cat Herding with PHP Generators
A Functional Guide to Cat Herding with PHP GeneratorsA Functional Guide to Cat Herding with PHP Generators
A Functional Guide to Cat Herding with PHP GeneratorsMark Baker
 
Mirror, mirror on the wall: Building a new PHP reflection library (DPC 2016)
Mirror, mirror on the wall: Building a new PHP reflection library (DPC 2016)Mirror, mirror on the wall: Building a new PHP reflection library (DPC 2016)
Mirror, mirror on the wall: Building a new PHP reflection library (DPC 2016)James Titcumb
 
関西PHP勉強会 php5.4つまみぐい
関西PHP勉強会 php5.4つまみぐい関西PHP勉強会 php5.4つまみぐい
関西PHP勉強会 php5.4つまみぐいHisateru Tanaka
 
Typed Properties and more: What's coming in PHP 7.4?
Typed Properties and more: What's coming in PHP 7.4?Typed Properties and more: What's coming in PHP 7.4?
Typed Properties and more: What's coming in PHP 7.4?Nikita Popov
 
Php pattern matching
Php pattern matchingPhp pattern matching
Php pattern matchingJIGAR MAKHIJA
 
Class 3 - PHP Functions
Class 3 - PHP FunctionsClass 3 - PHP Functions
Class 3 - PHP FunctionsAhmed Swilam
 

What's hot (20)

SPL: The Missing Link in Development
SPL: The Missing Link in DevelopmentSPL: The Missing Link in Development
SPL: The Missing Link in Development
 
PHP Tips for certification - OdW13
PHP Tips for certification - OdW13PHP Tips for certification - OdW13
PHP Tips for certification - OdW13
 
PHP Enums - PHPCon Japan 2021
PHP Enums - PHPCon Japan 2021PHP Enums - PHPCon Japan 2021
PHP Enums - PHPCon Japan 2021
 
Php string function
Php string function Php string function
Php string function
 
Building Testable PHP Applications
Building Testable PHP ApplicationsBuilding Testable PHP Applications
Building Testable PHP Applications
 
Just-In-Time Compiler in PHP 8
Just-In-Time Compiler in PHP 8Just-In-Time Compiler in PHP 8
Just-In-Time Compiler in PHP 8
 
php 2 Function creating, calling, PHP built-in function
php 2 Function creating, calling,PHP built-in functionphp 2 Function creating, calling,PHP built-in function
php 2 Function creating, calling, PHP built-in function
 
Workshop unittesting
Workshop unittestingWorkshop unittesting
Workshop unittesting
 
Functions in PHP
Functions in PHPFunctions in PHP
Functions in PHP
 
What's new in PHP 8.0?
What's new in PHP 8.0?What's new in PHP 8.0?
What's new in PHP 8.0?
 
Arrays &amp; functions in php
Arrays &amp; functions in phpArrays &amp; functions in php
Arrays &amp; functions in php
 
Static Optimization of PHP bytecode (PHPSC 2017)
Static Optimization of PHP bytecode (PHPSC 2017)Static Optimization of PHP bytecode (PHPSC 2017)
Static Optimization of PHP bytecode (PHPSC 2017)
 
Perl.Hacks.On.Vim
Perl.Hacks.On.VimPerl.Hacks.On.Vim
Perl.Hacks.On.Vim
 
A Functional Guide to Cat Herding with PHP Generators
A Functional Guide to Cat Herding with PHP GeneratorsA Functional Guide to Cat Herding with PHP Generators
A Functional Guide to Cat Herding with PHP Generators
 
Mirror, mirror on the wall: Building a new PHP reflection library (DPC 2016)
Mirror, mirror on the wall: Building a new PHP reflection library (DPC 2016)Mirror, mirror on the wall: Building a new PHP reflection library (DPC 2016)
Mirror, mirror on the wall: Building a new PHP reflection library (DPC 2016)
 
関西PHP勉強会 php5.4つまみぐい
関西PHP勉強会 php5.4つまみぐい関西PHP勉強会 php5.4つまみぐい
関西PHP勉強会 php5.4つまみぐい
 
Typed Properties and more: What's coming in PHP 7.4?
Typed Properties and more: What's coming in PHP 7.4?Typed Properties and more: What's coming in PHP 7.4?
Typed Properties and more: What's coming in PHP 7.4?
 
Php pattern matching
Php pattern matchingPhp pattern matching
Php pattern matching
 
PHP 7
PHP 7PHP 7
PHP 7
 
Class 3 - PHP Functions
Class 3 - PHP FunctionsClass 3 - PHP Functions
Class 3 - PHP Functions
 

Similar to Preparing for the next PHP version (5.6)

PHP 5.3 Overview
PHP 5.3 OverviewPHP 5.3 Overview
PHP 5.3 Overviewjsmith92
 
The why and how of moving to php 5.4/5.5
The why and how of moving to php 5.4/5.5The why and how of moving to php 5.4/5.5
The why and how of moving to php 5.4/5.5Wim Godden
 
The why and how of moving to PHP 5.4/5.5
The why and how of moving to PHP 5.4/5.5The why and how of moving to PHP 5.4/5.5
The why and how of moving to PHP 5.4/5.5Wim Godden
 
Can't Miss Features of PHP 5.3 and 5.4
Can't Miss Features of PHP 5.3 and 5.4Can't Miss Features of PHP 5.3 and 5.4
Can't Miss Features of PHP 5.3 and 5.4Jeff Carouth
 
Practical PHP 5.3
Practical PHP 5.3Practical PHP 5.3
Practical PHP 5.3Nate Abele
 
PHP-03-Functions.ppt
PHP-03-Functions.pptPHP-03-Functions.ppt
PHP-03-Functions.pptJamers2
 
Preparing for the next php version
Preparing for the next php versionPreparing for the next php version
Preparing for the next php versionDamien Seguy
 
Introducing PHP Latest Updates
Introducing PHP Latest UpdatesIntroducing PHP Latest Updates
Introducing PHP Latest UpdatesIftekhar Eather
 
Quality assurance for php projects with PHPStorm
Quality assurance for php projects with PHPStormQuality assurance for php projects with PHPStorm
Quality assurance for php projects with PHPStormMichelangelo van Dam
 
Lithium: The Framework for People Who Hate Frameworks, Tokyo Edition
Lithium: The Framework for People Who Hate Frameworks, Tokyo EditionLithium: The Framework for People Who Hate Frameworks, Tokyo Edition
Lithium: The Framework for People Who Hate Frameworks, Tokyo EditionNate Abele
 
Giới thiệu PHP 7
Giới thiệu PHP 7Giới thiệu PHP 7
Giới thiệu PHP 7ZendVN
 
Php 7 errors messages
Php 7 errors messagesPhp 7 errors messages
Php 7 errors messagesDamien Seguy
 
Mastering Namespaces in PHP
Mastering Namespaces in PHPMastering Namespaces in PHP
Mastering Namespaces in PHPNick Belhomme
 
PHP traits, treat or threat?
PHP traits, treat or threat?PHP traits, treat or threat?
PHP traits, treat or threat?Nick Belhomme
 
Php 7 compliance workshop singapore
Php 7 compliance workshop singaporePhp 7 compliance workshop singapore
Php 7 compliance workshop singaporeDamien Seguy
 
All I Need to Know I Learned by Writing My Own Web Framework
All I Need to Know I Learned by Writing My Own Web FrameworkAll I Need to Know I Learned by Writing My Own Web Framework
All I Need to Know I Learned by Writing My Own Web FrameworkBen Scofield
 

Similar to Preparing for the next PHP version (5.6) (20)

PHP 5.3 Overview
PHP 5.3 OverviewPHP 5.3 Overview
PHP 5.3 Overview
 
The why and how of moving to php 5.4/5.5
The why and how of moving to php 5.4/5.5The why and how of moving to php 5.4/5.5
The why and how of moving to php 5.4/5.5
 
The why and how of moving to PHP 5.4/5.5
The why and how of moving to PHP 5.4/5.5The why and how of moving to PHP 5.4/5.5
The why and how of moving to PHP 5.4/5.5
 
Can't Miss Features of PHP 5.3 and 5.4
Can't Miss Features of PHP 5.3 and 5.4Can't Miss Features of PHP 5.3 and 5.4
Can't Miss Features of PHP 5.3 and 5.4
 
Practical PHP 5.3
Practical PHP 5.3Practical PHP 5.3
Practical PHP 5.3
 
PHP-03-Functions.ppt
PHP-03-Functions.pptPHP-03-Functions.ppt
PHP-03-Functions.ppt
 
PHP-03-Functions.ppt
PHP-03-Functions.pptPHP-03-Functions.ppt
PHP-03-Functions.ppt
 
Preparing for the next php version
Preparing for the next php versionPreparing for the next php version
Preparing for the next php version
 
Introducing PHP Latest Updates
Introducing PHP Latest UpdatesIntroducing PHP Latest Updates
Introducing PHP Latest Updates
 
Quality assurance for php projects with PHPStorm
Quality assurance for php projects with PHPStormQuality assurance for php projects with PHPStorm
Quality assurance for php projects with PHPStorm
 
Lithium: The Framework for People Who Hate Frameworks, Tokyo Edition
Lithium: The Framework for People Who Hate Frameworks, Tokyo EditionLithium: The Framework for People Who Hate Frameworks, Tokyo Edition
Lithium: The Framework for People Who Hate Frameworks, Tokyo Edition
 
Giới thiệu PHP 7
Giới thiệu PHP 7Giới thiệu PHP 7
Giới thiệu PHP 7
 
php AND MYSQL _ppt.pdf
php AND MYSQL _ppt.pdfphp AND MYSQL _ppt.pdf
php AND MYSQL _ppt.pdf
 
Php Tutorials for Beginners
Php Tutorials for BeginnersPhp Tutorials for Beginners
Php Tutorials for Beginners
 
Slide
SlideSlide
Slide
 
Php 7 errors messages
Php 7 errors messagesPhp 7 errors messages
Php 7 errors messages
 
Mastering Namespaces in PHP
Mastering Namespaces in PHPMastering Namespaces in PHP
Mastering Namespaces in PHP
 
PHP traits, treat or threat?
PHP traits, treat or threat?PHP traits, treat or threat?
PHP traits, treat or threat?
 
Php 7 compliance workshop singapore
Php 7 compliance workshop singaporePhp 7 compliance workshop singapore
Php 7 compliance workshop singapore
 
All I Need to Know I Learned by Writing My Own Web Framework
All I Need to Know I Learned by Writing My Own Web FrameworkAll I Need to Know I Learned by Writing My Own Web Framework
All I Need to Know I Learned by Writing My Own Web Framework
 

More from Damien Seguy

Strong typing @ php leeds
Strong typing  @ php leedsStrong typing  @ php leeds
Strong typing @ php leedsDamien Seguy
 
Strong typing : adoption, adaptation and organisation
Strong typing : adoption, adaptation and organisationStrong typing : adoption, adaptation and organisation
Strong typing : adoption, adaptation and organisationDamien Seguy
 
Qui a laissé son mot de passe dans le code
Qui a laissé son mot de passe dans le codeQui a laissé son mot de passe dans le code
Qui a laissé son mot de passe dans le codeDamien Seguy
 
Analyse statique et applications
Analyse statique et applicationsAnalyse statique et applications
Analyse statique et applicationsDamien Seguy
 
Top 10 pieges php afup limoges
Top 10 pieges php   afup limogesTop 10 pieges php   afup limoges
Top 10 pieges php afup limogesDamien Seguy
 
Top 10 php classic traps DPC 2020
Top 10 php classic traps DPC 2020Top 10 php classic traps DPC 2020
Top 10 php classic traps DPC 2020Damien Seguy
 
Meilleur du typage fort (AFUP Day, 2020)
Meilleur du typage fort (AFUP Day, 2020)Meilleur du typage fort (AFUP Day, 2020)
Meilleur du typage fort (AFUP Day, 2020)Damien Seguy
 
Top 10 php classic traps confoo
Top 10 php classic traps confooTop 10 php classic traps confoo
Top 10 php classic traps confooDamien Seguy
 
Tout pour se préparer à PHP 7.4
Tout pour se préparer à PHP 7.4Tout pour se préparer à PHP 7.4
Tout pour se préparer à PHP 7.4Damien Seguy
 
Top 10 php classic traps php serbia
Top 10 php classic traps php serbiaTop 10 php classic traps php serbia
Top 10 php classic traps php serbiaDamien Seguy
 
Top 10 php classic traps
Top 10 php classic trapsTop 10 php classic traps
Top 10 php classic trapsDamien Seguy
 
Top 10 chausse trappes
Top 10 chausse trappesTop 10 chausse trappes
Top 10 chausse trappesDamien Seguy
 
Code review workshop
Code review workshopCode review workshop
Code review workshopDamien Seguy
 
Understanding static analysis php amsterdam 2018
Understanding static analysis   php amsterdam 2018Understanding static analysis   php amsterdam 2018
Understanding static analysis php amsterdam 2018Damien Seguy
 
Review unknown code with static analysis php ce 2018
Review unknown code with static analysis   php ce 2018Review unknown code with static analysis   php ce 2018
Review unknown code with static analysis php ce 2018Damien Seguy
 
Everything new with PHP 7.3
Everything new with PHP 7.3Everything new with PHP 7.3
Everything new with PHP 7.3Damien Seguy
 
Php 7.3 et ses RFC (AFUP Toulouse)
Php 7.3 et ses RFC  (AFUP Toulouse)Php 7.3 et ses RFC  (AFUP Toulouse)
Php 7.3 et ses RFC (AFUP Toulouse)Damien Seguy
 
Tout sur PHP 7.3 et ses RFC
Tout sur PHP 7.3 et ses RFCTout sur PHP 7.3 et ses RFC
Tout sur PHP 7.3 et ses RFCDamien Seguy
 
Review unknown code with static analysis php ipc 2018
Review unknown code with static analysis   php ipc 2018Review unknown code with static analysis   php ipc 2018
Review unknown code with static analysis php ipc 2018Damien Seguy
 
Code review for busy people
Code review for busy peopleCode review for busy people
Code review for busy peopleDamien Seguy
 

More from Damien Seguy (20)

Strong typing @ php leeds
Strong typing  @ php leedsStrong typing  @ php leeds
Strong typing @ php leeds
 
Strong typing : adoption, adaptation and organisation
Strong typing : adoption, adaptation and organisationStrong typing : adoption, adaptation and organisation
Strong typing : adoption, adaptation and organisation
 
Qui a laissé son mot de passe dans le code
Qui a laissé son mot de passe dans le codeQui a laissé son mot de passe dans le code
Qui a laissé son mot de passe dans le code
 
Analyse statique et applications
Analyse statique et applicationsAnalyse statique et applications
Analyse statique et applications
 
Top 10 pieges php afup limoges
Top 10 pieges php   afup limogesTop 10 pieges php   afup limoges
Top 10 pieges php afup limoges
 
Top 10 php classic traps DPC 2020
Top 10 php classic traps DPC 2020Top 10 php classic traps DPC 2020
Top 10 php classic traps DPC 2020
 
Meilleur du typage fort (AFUP Day, 2020)
Meilleur du typage fort (AFUP Day, 2020)Meilleur du typage fort (AFUP Day, 2020)
Meilleur du typage fort (AFUP Day, 2020)
 
Top 10 php classic traps confoo
Top 10 php classic traps confooTop 10 php classic traps confoo
Top 10 php classic traps confoo
 
Tout pour se préparer à PHP 7.4
Tout pour se préparer à PHP 7.4Tout pour se préparer à PHP 7.4
Tout pour se préparer à PHP 7.4
 
Top 10 php classic traps php serbia
Top 10 php classic traps php serbiaTop 10 php classic traps php serbia
Top 10 php classic traps php serbia
 
Top 10 php classic traps
Top 10 php classic trapsTop 10 php classic traps
Top 10 php classic traps
 
Top 10 chausse trappes
Top 10 chausse trappesTop 10 chausse trappes
Top 10 chausse trappes
 
Code review workshop
Code review workshopCode review workshop
Code review workshop
 
Understanding static analysis php amsterdam 2018
Understanding static analysis   php amsterdam 2018Understanding static analysis   php amsterdam 2018
Understanding static analysis php amsterdam 2018
 
Review unknown code with static analysis php ce 2018
Review unknown code with static analysis   php ce 2018Review unknown code with static analysis   php ce 2018
Review unknown code with static analysis php ce 2018
 
Everything new with PHP 7.3
Everything new with PHP 7.3Everything new with PHP 7.3
Everything new with PHP 7.3
 
Php 7.3 et ses RFC (AFUP Toulouse)
Php 7.3 et ses RFC  (AFUP Toulouse)Php 7.3 et ses RFC  (AFUP Toulouse)
Php 7.3 et ses RFC (AFUP Toulouse)
 
Tout sur PHP 7.3 et ses RFC
Tout sur PHP 7.3 et ses RFCTout sur PHP 7.3 et ses RFC
Tout sur PHP 7.3 et ses RFC
 
Review unknown code with static analysis php ipc 2018
Review unknown code with static analysis   php ipc 2018Review unknown code with static analysis   php ipc 2018
Review unknown code with static analysis php ipc 2018
 
Code review for busy people
Code review for busy peopleCode review for busy people
Code review for busy people
 

Recently uploaded

"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii SoldatenkoFwdays
 
Gen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfGen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfAddepto
 
Dev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebDev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebUiPathCommunity
 
Pigging Solutions Piggable Sweeping Elbows
Pigging Solutions Piggable Sweeping ElbowsPigging Solutions Piggable Sweeping Elbows
Pigging Solutions Piggable Sweeping ElbowsPigging Solutions
 
Human Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsHuman Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsMark Billinghurst
 
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks..."LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...Fwdays
 
Vertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering TipsVertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering TipsMiki Katsuragi
 
Scanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsScanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsRizwan Syed
 
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)Bun (KitWorks Team Study 노별마루 발표 2024.4.22)
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)Wonjun Hwang
 
Connect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationConnect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationSlibray Presentation
 
Build your next Gen AI Breakthrough - April 2024
Build your next Gen AI Breakthrough - April 2024Build your next Gen AI Breakthrough - April 2024
Build your next Gen AI Breakthrough - April 2024Neo4j
 
Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024Enterprise Knowledge
 
SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024Lorenzo Miniero
 
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...Patryk Bandurski
 
Artificial intelligence in the post-deep learning era
Artificial intelligence in the post-deep learning eraArtificial intelligence in the post-deep learning era
Artificial intelligence in the post-deep learning eraDeakin University
 
Bluetooth Controlled Car with Arduino.pdf
Bluetooth Controlled Car with Arduino.pdfBluetooth Controlled Car with Arduino.pdf
Bluetooth Controlled Car with Arduino.pdfngoud9212
 
Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Mattias Andersson
 
"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr BaganFwdays
 

Recently uploaded (20)

"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko
 
Gen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfGen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdf
 
Dev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebDev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio Web
 
DMCC Future of Trade Web3 - Special Edition
DMCC Future of Trade Web3 - Special EditionDMCC Future of Trade Web3 - Special Edition
DMCC Future of Trade Web3 - Special Edition
 
Pigging Solutions Piggable Sweeping Elbows
Pigging Solutions Piggable Sweeping ElbowsPigging Solutions Piggable Sweeping Elbows
Pigging Solutions Piggable Sweeping Elbows
 
Vulnerability_Management_GRC_by Sohang Sengupta.pptx
Vulnerability_Management_GRC_by Sohang Sengupta.pptxVulnerability_Management_GRC_by Sohang Sengupta.pptx
Vulnerability_Management_GRC_by Sohang Sengupta.pptx
 
Human Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsHuman Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR Systems
 
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks..."LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
 
Vertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering TipsVertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering Tips
 
Scanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsScanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL Certs
 
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)Bun (KitWorks Team Study 노별마루 발표 2024.4.22)
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)
 
Connect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationConnect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck Presentation
 
Build your next Gen AI Breakthrough - April 2024
Build your next Gen AI Breakthrough - April 2024Build your next Gen AI Breakthrough - April 2024
Build your next Gen AI Breakthrough - April 2024
 
Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024
 
SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024
 
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
 
Artificial intelligence in the post-deep learning era
Artificial intelligence in the post-deep learning eraArtificial intelligence in the post-deep learning era
Artificial intelligence in the post-deep learning era
 
Bluetooth Controlled Car with Arduino.pdf
Bluetooth Controlled Car with Arduino.pdfBluetooth Controlled Car with Arduino.pdf
Bluetooth Controlled Car with Arduino.pdf
 
Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?
 
"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan
 

Preparing for the next PHP version (5.6)

  • 1. Preparing for the next PHP version
  • 2. Towards PHP 5.5 and 5.6 • Changing version is often a big challenge • Backward incompatibilities • New features • How to spot them ?
  • 3. Speaker • Damien Seguy • CTO at exakat • Phather of the plush toy elePHPant • Will talk on automated code audit later
  • 4. PHP linting • command line : php -l filename.php • Will only parse the code, • not execution • Will spot compilation problems
  • 5.
  • 6. PHP lint will find • Short array syntax • Function subscripting • break/continue with variables • Rare other situations • Code that won’t compile anyway
  • 7. Where else code will break? • PHP running has 3 stages • parsed • compiled • executed Checked with lint Checked code review Checked with data and UT
  • 8. What will change? • Removed features • Deprecated features • Changed features • New features
  • 9. Deprecated features • PHP 5.6 • $HTTP_RAW_POST_DATA 5.6 • Call From Incompatible Context • iconv and mbstring directives go to default_charset • PHP 5.5 • /e in preg_replace • ext/mysql 5.5 • mcrypt arguments
  • 10. Deprecated features • $HTTP_RAW_POST_DATA • Replace it by php://input • php://input is now reusable • ext/mysql • Look for mysql_* functions • Probably in Db/Adapter 5.6 5.5
  • 11. Search is your friend • Grep, or IDE’s search function will help you • Look for mysql_* • $HTTP_RAW_POST_DATA
  • 12. Error_level to E_STRICT Deprecated: The mysql extension is deprecated and will be removed in the future: use mysqli or PDO instead in /path/to/filename.php on line 11
  • 13. /e and charset directives • preg_replace(‘/ /e’, ‘evaled code’, $haystack) • replaced preg_replace_callback(‘/ /‘, closure, $haystack) • in php.ini, check for mbstring, iconv and default_charset 5.5 5.6
  • 14. Where to look for • preg_replace • Search for preg_replace function calls • defaut_charset • Search for ini_set, ini_get, ini_get_all, ini_restore, get_cfg_var • Seach in php.ini, .htaccess
  • 15. Incompatible context $ php53 test.php Notice: Undefined variable: this in test.php on line 3 A <?php class A { function f() { echo get_class($this); } } A::f(); ?> 5.6 $ php56 test.php Strict Standards: Non-static method A::f() should not be called statically in /Users/famille/Desktop/test.php on line 6 Notice: Undefined variable: this in test.php on line 3 A
  • 16. Search for situations • Search for :: operator • Get the class • then the method • then the static keyword • Needs a automated auditing tool • Code sniffer, IDE
  • 17. Strict Standards: Non-static method A::f() should not be called statically in test.php on line 6
  • 18. Changed behavior • json_decode is stricter • it was more tolerant before with TRUE or False values • gmp resources are object • and not resources • search for is_resource() • mcrypt requires valid keys and vectors • check correct size and vector presence • pack and unpack • More compatible with Perl • Z and a format code must be checked 5.6 5.5
  • 19. Added structures • PHP adds • constants • functions • extensions • traits • interfaces
  • 20. Added structures Functions Classes Constants 5.3 25 18 80 5.4 0 9 78 5.5 113 9 37 5.6 19 0 24 Total 157 36 219
  • 21. New features • Fixing • Modernization • New feature
  • 23. empty() upgrade • No need anymore to expressions in a variable for empty()! function myFunction() { return -2 ; } if (empty(myFunction() + 2)) { echo "This means 0!n"; } Fatal error: Can't use function return value in write context in test.php on line 6 5.5
  • 24. SELF::const != self::const <?php class object { const x = 1; function x() { print SELF::x."n"; } } $object = new object(); $object->x(); ?> Fatal error: Class 'SELF' not found in test.php on line 6 5.5
  • 26. Dereferencing • Direct access to element in a string or an array. <?php /// Function dereferencing echo str_split("123", 1 )[2]; echo "n"; /// Array dereferencing echo [5, 5, 3][0]; echo "n"; /// String dereferencing echo 'PHP'[0]; echo "n"; 5.5 ?>
  • 27. Power operator • Replaces pow() • Be aware of precedence echo pow(2, 3); $a=2; $a **= 3; $a = 2 ** 3; 5.6
  • 28. … Variadic • replaces func_get_args() • Easier to read function array_power($pow, ...$integers) { foreach($integers as $i) { print "$i ^ $pow = ". ($i ** $pow)."n"; } } array_power(3, 1, 2, 3, 4, 5); 1 ^ 3 = 1 2 ^ 3 = 8 3 ^ 3 = 27 4 ^ 3 = 64 5 ^ 3 = 125 5.6
  • 29. Variadic … • replaces call_user_func_array • Easier to read • Works on functions • Works with typehint • Doesn’t work with references function array_power($pow, ...$integers) { foreach($integers as $i) { print "$i ^ $pow = ". ($i ** $pow)."n"; } } array_power(3, ...range(1, 5)); array_power(3, ...[1, 2, 3, 4, 5]); array_power(3, ...[1, 2, 3], ...[4, 5]); 1 ^ 3 = 1 2 ^ 3 = 8 3 ^ 3 = 27 4 ^ 3 = 64 5 ^ 3 = 125
  • 30. Generators function factors($limit) { $r = array(2); for ($i = 3; $i <= $limit; $i += 2) { $r[] = $i; } return $r; } $prime = 135; foreach (factors(sqrt($prime)) as $n) { echo "$n ". ($prime % $n ? ' not ' : '') . " factor} • $step big => huge memory usage 5.5
  • 31. Generators • New yield keyword • Save memory from n down to 1 value • Good for long or infinite loops • Search for range(), for() or loops function factors($limit) { yield 2; for ($i = 3; $i <= $limit; $i += 2) { yield $i; } } $prime = 135; foreach (factors(sqrt($prime)) as $n) { echo "$n ". ($prime % $n ? ' not ' : '') . " factor}
  • 32. function x() { $r = new resource(); Finally try { $result = $r->do(); } catch (NetworkException $e) { unset ($r); throw $e; } catch (UnexpectedException $e) { unset ($r); throw $e; } catch (DaylightSavingException $e) { unset ($r); throw $e; } unset ($r); return $result; } • Clean up after exception • What if return in try? • Move cleaning to __destruct()? 5.5
  • 33. Finally • Clean up after exception or not • Clean up even when return too early function x() { $r = new resource(); try { $result = $r->do(); } catch (NetworkException $e) { throw $e; } catch (UnexpectedException $e) { throw $e; } catch (DaylightSavingException $e) { // just ignore this one } finally { unset ($r) ; } return $result; }
  • 35. Class name resolution <?php namespace NameSpace; class ClassName {} echo ClassName::class; echo "n"; ?> • Get the full name of a class with ::class 5.5
  • 36. class somePasswordSa_fe {_ debugInfo() private $user; private $password; public function __construct($user, $password) { $this->user = $user; $this->password = $password; } public function __debugInfo() { return [ 'user' => $this->password, 'password' => '**********', ]; } } print_r(new somePasswordSafe('root', 'secret')); somePasswordSafe Object ( [user] => secret [password] => ********** ) 5.6
  • 37. use const / functions namespace NameSpace { const FOO = 42; function f() { echo __FUNCTION__."n"; } } namespace { use const NameSpaceFOO; use function NameSpacef; echo FOO."n"; f(); } • Importing constants or functions from another namespace • Keep things separated • Avoid polluting global namespace • Avoid static only classes 5.6
  • 38. Constant scalar expressions class Version { const MAJOR = 2; const MIDDLE = ONE; const MINOR = 1; const FULL = Version::MAJOR.'.'.Version::MIDDLE.'.'.Version::MINOR.'-'.PHP_VERSION; const SHORT = Version::MAJOR.'.'.Version::MIDDLE; const COMPACT = Version::MAJOR.Version::MIDDLE.Version::MINOR; public function f($a = (MAJOR == 2) ? 3 : Version::MINOR ** 3) { return $a; } } • Code automation • Won’t accept functioncalls • Keep it simple 5.6
  • 39. Foreach supports list • And any type <?php of keys • Good with Iterator classes • Not possible with Arrays class object implements Iterator { /.../ function key() { return array(1,2); } function current() { return 3; } /.../ } $object = new object(); foreach($object as list($a, $b) = $c) { print "$a + $b + $c = ".($a + $b + $c)."n"; } ?> 5.5
  • 40. Context changes • PHP 5.6 • Windows XP and 2003 dropped • Support for Zend Optimiser • PHP 5.5 • phpdbg • Large File Upload 5.5 5.6