SlideShare une entreprise Scribd logo
1  sur  42
Télécharger pour lire hors ligne
The Why and How of moving to PHP 5.4
Who am I ?
Wim Godden (@wimgtr)
Founder of Cu.be Solutions (http://cu.be)
Open Source developer since 1997
Developer of OpenX, PHPCompatibility, Nginx extensions, ...
Zend Certified Engineer
Zend Framework Certified Engineer
MySQL Certified Developer
Speaker at PHP and 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.5RC1
6.0 (just kidding)
The numbers
W3Techs (http://w3techs.com/technologies/details/pl-php/all/all)
PHP 4 : 2.7%
PHP 5 : 97.2%
5.0 : 0.1%
5.1 : 2.6%
5.2 : 43.5%
5.3 : 49.7%
5.4 : 4.1%
5.5 : < 0.1 %
5.3 quick recap
Namespaces ()
Late static binding
Closures
Better garbage collection
Goto
Mysqlnd
Performance gain
5.3 – people are not even using it !
43.5% still on PHP 5.2
No :
Symfony 2
Zend Framework 2
Other frameworks that need namespaces
Problematic for developers
PHP 5.4 – what's changed ?
New features
Performance and memory usage
Improved consistency
Some things removed
Exciting new things – short array syntax
$yourItems = array('a', 'b', 'c', 'd');
$yourItems = ['a', 'b', 'c', 'd'];
$yourItems = ['a' => 5, 'b' => 3];
Exciting new things – function array dereferencing
function getCars()
{
return array(
'Mini',
'Smart',
'Volvo',
'BMW'
);
}
$cars = getCars();
echo $cars[1];
function getCars()
{
return [
'Mini',
'Smart',
'Volvo',
'BMW'
];
}
echo getCars()[1];
Exciting new things – Traits
Reuse methods across classes
Classes have no common parent
Traits - example
Log output : abcd
trait Logger
{
public function log($data) { echo "Log output : " . $data; }
}
class SomeClass {
use Logger;
}
$someObject = new SomeClass();
$someObject->log('abcd');
Traits - example
class SomeClass {
public function log($data) { echo "Log output : " . $data; }
}
$someObject = new SomeClass();
$someObject->log('abcd');
Traits – careful !
trait Logger {
private $foo;
}
class SomeClass {
private $foo;
use Logger;
}
will throw E_STRICT !
Exciting new things – Webserver
PHP 5.4 has a built-in webserver
Development only !
Handles requests sequentially
Ideal for quick testing
Ideal for unit testing of webservices
Webserver – how to
/var/www/php54test/html> php -S localhost:8000
PHP 5.4.15 Development Server started at Sat May 2 00:41:12 2013
Listening on http://localhost:8000
Document root is /var/www/php54test/html
Press Ctrl-C to quit.
/var/www/php54test/html> php -S localhost:8000 -t /var/www/other-path/html
PHP 5.4.15 Development Server started at Sat May 2 00:41:12 2013
Listening on http://localhost:8000
Document root is /var/www/other-path/html
Press Ctrl-C to quit.
/var/www/php54test/html> php -S localhost:8000 bootstrap.php
PHP 5.4.15 Development Server started at Sat May 2 00:41:12 2013
Listening on http://localhost:8000
Document root is /var/www/php54test/html
Press Ctrl-C to quit.
Exciting new things – SessionHandler
New session handling class
Groups all methods for session handling :
close()
destroy()
gc()
open()
read()
write()
SessionHandler
class MySessionHandler extends SessionHandler
{
public function read($session_id)
{
// Get the session data
}
public function write($session_id, $session_data)
{
// Set the session data
}
...
}
$handler = new MySessionHandler();
session_set_save_handler($handler, true);
session_start();
Exciting new things – more session stuff
File upload extension
→ file upload registers in session
→ readable through AJAX calls
New function session_status()
Return values : PHP_SESSION_ACTIVE / PHP_SESSION_NONE
Performance and memory usage
Performance : 10 – 30%
How ?
Core optimizations
New internal caches (functions, constants, …)
Better (un)serialization
Inlining often-used code paths
…
Reduced memory usage : up to 50% !
Big impact on large frameworks
Even bigger impact on codebases such as Drupal
What else is new ? (1/3)
Binary notation
Decimal : 123
Octal : 0173
Hex : 0x7B
Binary : 0b1111011
Class member access on object instantiation
`$fooObj = new Foo();
echo $fooObj->bar();
echo (new Foo)->bar();
What else is new ? (2/3)
class Cat {
private $meows;
function __construct($meows) {
$this->meows = $meows;
}
function __invoke() {
return str_repeat('Meow!', $this->meows);
}
}
$furbal = new Cat(5);
echo $furbal(); // Outputs: Meow!Meow!Meow!Meow!Meow!
Magic method __invoke() :
What else is new ? (3/3)
class someClass {
private $someProperty;
function __construct($value) {
$this->someProperty = $value;
}
public function showMeTheMoney() {
return function() { echo '$' . $this->someProperty; };
}
}
$obj = new someClass(5000);;
$func = $obj->showMeTheMoney();
$func(); // Outputs: $5000
$objA = new someClass(5000);
$objB = new someClass(10000);
$func = $objA->showMeTheMoney();
$func(); // Outputs: $5000
$func = $func->bindTo($objB);
$func(); // Outputs: $10000
5.3 :
5.4 :
Other changes
Error handling :
5.3 : Parse error: syntax error, unexpected T_STRING, expecting '{' in index.php on line 1
5.4 : Parse error: syntax error, unexpected 'bar' (T_STRING), expecting '{' in index.php on line 1
Array to string conversion :
5.3 : Array
5.4 : Note: Array to string conversion in test.php on line 8
<?= always works (even with short_tags off)
Default charset = UTF8
class foo bar
$var = array();
echo $var;
Time to remove !
register_globals
magic_quotes
safe_mode
Removed : Still working :
break $var; break 2;
continue $var; continue 3;
session_register()
session_unregister()
session_is_registered()
→ use $_SESSION
More stuff removed
Timezone guessing → date.timezone in php.ini
sqlite extension → use sqlite3
New reserved keywords :
trait
insteadof
callable
So...
Should you upgrade today ?
Upgrade : yes / no
Yes No
Using removed extensions x
Using removed functions x
Need extra performance / reduced memory x
Really need new feature x
No unit tests x
No package available (.rpm, .deb, ...) x
Postponing upgrades
End-Of-Life
In the past : we'll see
Now : minor release + 2 = out → EOL
5.5 = OUT → 5.3 = EOL (soon !)
5.6 = OUT → 5.4 = EOL (next year !)
Critical security patches : 1 year
No bugfixes
Framework support
Developer motivation
So you want to upgrade...
Option 1 : run your unit tests
Option 2 : visit each page (good luck !) + check error_log
Option 3 : automate it !
Back in 2010...
PHP Architect @ Belgian Railways
8 years of legacy code
40+ different developers
40+ projects
Challenge :
migrate all projects from
PHP 5.2.4 (on Solaris)
to
PHP 5.3.x (on Linux)
The idea
Automate it
How ? → Use the CI environment
Which tool ? → PHP_CodeSniffer
PHP_CodeSniffer
Detect 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
PHP_CodeSniffer
Let's see what it looks like
PHPCompatibility
New 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.1, 5.2, 5.3, 5.4 and 5.5
PHPCompatibility – making it work
Via GIT :
git clone git://github.com/wimg/PHPCompatibility.git PHPCompatibility
Download from Github :
http://github.com/wimg/PHPCompatibility
Install in <pear_dir>/PHP/CodeSniffer/Standards
Run :
phpcs --standard=PHPCompatibility <path>
Important notes
Large directories → can be slow !
Use --extensions=php,phtml
No point scanning .js files
Test PHP 5.4 compatibility → need PHP 5.4 on the system
Static analysis
Doesn't run code
Can not detect every single incompatibility
Provides filename and line number
The result
Zend Framework 1.7 app
PHP 5.2 : working fine
PHP 5.3 : fail !
function goto()
No 100% detection
95% automation = lots of time saved !
Questions ?
Questions ?
Contact
Twitter @wimgtr
Web http://techblog.wimgodden.be
Slides http://www.slideshare.net/wimg
E-mail wim.godden@cu.be
Please...
Rate my talk : http://joind.in/8643
Thanks !
Please...
Rate my talk : http://joind.in/8643

Contenu connexe

Tendances

Php in 2013 (Web-5 2013 conference)
Php in 2013 (Web-5 2013 conference)Php in 2013 (Web-5 2013 conference)
Php in 2013 (Web-5 2013 conference)julien pauli
 
PHP 7 Crash Course - php[world] 2015
PHP 7 Crash Course - php[world] 2015PHP 7 Crash Course - php[world] 2015
PHP 7 Crash Course - php[world] 2015Colin O'Dell
 
Php 7 hhvm and co
Php 7 hhvm and coPhp 7 hhvm and co
Php 7 hhvm and coPierre Joye
 
PHP7 - Scalar Type Hints & Return Types
PHP7 - Scalar Type Hints & Return TypesPHP7 - Scalar Type Hints & Return Types
PHP7 - Scalar Type Hints & Return TypesEric Poe
 
What you need to remember when you upload to CPAN
What you need to remember when you upload to CPANWhat you need to remember when you upload to CPAN
What you need to remember when you upload to CPANcharsbar
 
PHP Tips for certification - OdW13
PHP Tips for certification - OdW13PHP Tips for certification - OdW13
PHP Tips for certification - OdW13julien pauli
 
Quick tour of PHP from inside
Quick tour of PHP from insideQuick tour of PHP from inside
Quick tour of PHP from insidejulien pauli
 
Preparing code for Php 7 workshop
Preparing code for Php 7 workshopPreparing code for Php 7 workshop
Preparing code for Php 7 workshopDamien Seguy
 
typemap in Perl/XS
typemap in Perl/XS  typemap in Perl/XS
typemap in Perl/XS charsbar
 
Mysqlnd, an unknown powerful PHP extension
Mysqlnd, an unknown powerful PHP extensionMysqlnd, an unknown powerful PHP extension
Mysqlnd, an unknown powerful PHP extensionjulien pauli
 
Nginx and friends - putting a turbo button on your site
Nginx and friends - putting a turbo button on your siteNginx and friends - putting a turbo button on your site
Nginx and friends - putting a turbo button on your siteWim Godden
 
The Php Life Cycle
The Php Life CycleThe Php Life Cycle
The Php Life CycleXinchen Hui
 
2016年のPerl (Long version)
2016年のPerl (Long version)2016年のPerl (Long version)
2016年のPerl (Long version)charsbar
 
PHP traits, treat or threat?
PHP traits, treat or threat?PHP traits, treat or threat?
PHP traits, treat or threat?Nick Belhomme
 
SDPHP - Percona Toolkit (It's Basically Magic)
SDPHP - Percona Toolkit (It's Basically Magic)SDPHP - Percona Toolkit (It's Basically Magic)
SDPHP - Percona Toolkit (It's Basically Magic)Robert Swisher
 
PHP 7.1 : elegance of our legacy
PHP 7.1 : elegance of our legacyPHP 7.1 : elegance of our legacy
PHP 7.1 : elegance of our legacyDamien Seguy
 
Better detection of what modules are used by some Perl 5 code
Better detection of what modules are used by some Perl 5 codeBetter detection of what modules are used by some Perl 5 code
Better detection of what modules are used by some Perl 5 codecharsbar
 

Tendances (20)

Php in 2013 (Web-5 2013 conference)
Php in 2013 (Web-5 2013 conference)Php in 2013 (Web-5 2013 conference)
Php in 2013 (Web-5 2013 conference)
 
PHP 7 Crash Course - php[world] 2015
PHP 7 Crash Course - php[world] 2015PHP 7 Crash Course - php[world] 2015
PHP 7 Crash Course - php[world] 2015
 
PHP7 is coming
PHP7 is comingPHP7 is coming
PHP7 is coming
 
Modern PHP
Modern PHPModern PHP
Modern PHP
 
Php 7 hhvm and co
Php 7 hhvm and coPhp 7 hhvm and co
Php 7 hhvm and co
 
PHP7 - Scalar Type Hints & Return Types
PHP7 - Scalar Type Hints & Return TypesPHP7 - Scalar Type Hints & Return Types
PHP7 - Scalar Type Hints & Return Types
 
What you need to remember when you upload to CPAN
What you need to remember when you upload to CPANWhat you need to remember when you upload to CPAN
What you need to remember when you upload to CPAN
 
PHP Tips for certification - OdW13
PHP Tips for certification - OdW13PHP Tips for certification - OdW13
PHP Tips for certification - OdW13
 
Quick tour of PHP from inside
Quick tour of PHP from insideQuick tour of PHP from inside
Quick tour of PHP from inside
 
Preparing code for Php 7 workshop
Preparing code for Php 7 workshopPreparing code for Php 7 workshop
Preparing code for Php 7 workshop
 
typemap in Perl/XS
typemap in Perl/XS  typemap in Perl/XS
typemap in Perl/XS
 
PHP5.5 is Here
PHP5.5 is HerePHP5.5 is Here
PHP5.5 is Here
 
Mysqlnd, an unknown powerful PHP extension
Mysqlnd, an unknown powerful PHP extensionMysqlnd, an unknown powerful PHP extension
Mysqlnd, an unknown powerful PHP extension
 
Nginx and friends - putting a turbo button on your site
Nginx and friends - putting a turbo button on your siteNginx and friends - putting a turbo button on your site
Nginx and friends - putting a turbo button on your site
 
The Php Life Cycle
The Php Life CycleThe Php Life Cycle
The Php Life Cycle
 
2016年のPerl (Long version)
2016年のPerl (Long version)2016年のPerl (Long version)
2016年のPerl (Long version)
 
PHP traits, treat or threat?
PHP traits, treat or threat?PHP traits, treat or threat?
PHP traits, treat or threat?
 
SDPHP - Percona Toolkit (It's Basically Magic)
SDPHP - Percona Toolkit (It's Basically Magic)SDPHP - Percona Toolkit (It's Basically Magic)
SDPHP - Percona Toolkit (It's Basically Magic)
 
PHP 7.1 : elegance of our legacy
PHP 7.1 : elegance of our legacyPHP 7.1 : elegance of our legacy
PHP 7.1 : elegance of our legacy
 
Better detection of what modules are used by some Perl 5 code
Better detection of what modules are used by some Perl 5 codeBetter detection of what modules are used by some Perl 5 code
Better detection of what modules are used by some Perl 5 code
 

Similaire à The why and how of moving to php 5.4

What To Expect From PHP7
What To Expect From PHP7What To Expect From PHP7
What To Expect From PHP7Codemotion
 
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
 
The why and how of moving to php 8
The why and how of moving to php 8The why and how of moving to php 8
The why and how of moving to php 8Wim Godden
 
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
 
Simplify your professional web development with symfony
Simplify your professional web development with symfonySimplify your professional web development with symfony
Simplify your professional web development with symfonyFrancois Zaninotto
 
An introduction to PHP 5.4
An introduction to PHP 5.4An introduction to PHP 5.4
An introduction to PHP 5.4Giovanni Derks
 
The new features of PHP 7 - Enrico Zimuel - Codemotion Milan 2016
The new features of PHP 7 - Enrico Zimuel - Codemotion Milan 2016The new features of PHP 7 - Enrico Zimuel - Codemotion Milan 2016
The new features of PHP 7 - Enrico Zimuel - Codemotion Milan 2016Codemotion
 
Workshop quality assurance for php projects tek12
Workshop quality assurance for php projects tek12Workshop quality assurance for php projects tek12
Workshop quality assurance for php projects tek12Michelangelo van Dam
 
Living With Legacy Code
Living With Legacy CodeLiving With Legacy Code
Living With Legacy CodeRowan Merewood
 
The why and how of moving to php 7.x
The why and how of moving to php 7.xThe why and how of moving to php 7.x
The why and how of moving to php 7.xWim Godden
 
The why and how of moving to php 7.x
The why and how of moving to php 7.xThe why and how of moving to php 7.x
The why and how of moving to php 7.xWim Godden
 
Fighting Fear-Driven-Development With PHPUnit
Fighting Fear-Driven-Development With PHPUnitFighting Fear-Driven-Development With PHPUnit
Fighting Fear-Driven-Development With PHPUnitJames Fuller
 
Php7 HHVM and co
Php7 HHVM and coPhp7 HHVM and co
Php7 HHVM and coweltling
 

Similaire à The why and how of moving to php 5.4 (20)

What To Expect From PHP7
What To Expect From PHP7What To Expect From PHP7
What To Expect From 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
 
The why and how of moving to php 8
The why and how of moving to php 8The why and how of moving to php 8
The why and how of moving to php 8
 
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
 
Simplify your professional web development with symfony
Simplify your professional web development with symfonySimplify your professional web development with symfony
Simplify your professional web development with symfony
 
Php 7 evolution
Php 7 evolutionPhp 7 evolution
Php 7 evolution
 
An introduction to PHP 5.4
An introduction to PHP 5.4An introduction to PHP 5.4
An introduction to PHP 5.4
 
The new features of PHP 7 - Enrico Zimuel - Codemotion Milan 2016
The new features of PHP 7 - Enrico Zimuel - Codemotion Milan 2016The new features of PHP 7 - Enrico Zimuel - Codemotion Milan 2016
The new features of PHP 7 - Enrico Zimuel - Codemotion Milan 2016
 
The new features of PHP 7
The new features of PHP 7The new features of PHP 7
The new features of PHP 7
 
Workshop quality assurance for php projects tek12
Workshop quality assurance for php projects tek12Workshop quality assurance for php projects tek12
Workshop quality assurance for php projects tek12
 
What's new with PHP7
What's new with PHP7What's new with PHP7
What's new with PHP7
 
Living With Legacy Code
Living With Legacy CodeLiving With Legacy Code
Living With Legacy Code
 
Migrating to PHP 7
Migrating to PHP 7Migrating to PHP 7
Migrating to PHP 7
 
The why and how of moving to php 7.x
The why and how of moving to php 7.xThe why and how of moving to php 7.x
The why and how of moving to php 7.x
 
The why and how of moving to php 7.x
The why and how of moving to php 7.xThe why and how of moving to php 7.x
The why and how of moving to php 7.x
 
ZendCon 08 php 5.3
ZendCon 08 php 5.3ZendCon 08 php 5.3
ZendCon 08 php 5.3
 
Listen afup 2010
Listen afup 2010Listen afup 2010
Listen afup 2010
 
Fighting Fear-Driven-Development With PHPUnit
Fighting Fear-Driven-Development With PHPUnitFighting Fear-Driven-Development With PHPUnit
Fighting Fear-Driven-Development With PHPUnit
 
50 shades of PHP
50 shades of PHP50 shades of PHP
50 shades of PHP
 
Php7 HHVM and co
Php7 HHVM and coPhp7 HHVM and co
Php7 HHVM and co
 

Plus de Wim Godden

Beyond php - it's not (just) about the code
Beyond php - it's not (just) about the codeBeyond php - it's not (just) about the code
Beyond php - it's not (just) about the codeWim Godden
 
Bringing bright ideas to life
Bringing bright ideas to lifeBringing bright ideas to life
Bringing bright ideas to lifeWim Godden
 
My app is secure... I think
My app is secure... I thinkMy app is secure... I think
My app is secure... I thinkWim Godden
 
My app is secure... I think
My app is secure... I thinkMy app is secure... I think
My app is secure... I thinkWim Godden
 
Building interactivity with websockets
Building interactivity with websocketsBuilding interactivity with websockets
Building interactivity with websocketsWim Godden
 
Bringing bright ideas to life
Bringing bright ideas to lifeBringing bright ideas to life
Bringing bright ideas to lifeWim Godden
 
Your app lives on the network - networking for web developers
Your app lives on the network - networking for web developersYour app lives on the network - networking for web developers
Your app lives on the network - networking for web developersWim Godden
 
Beyond php - it's not (just) about the code
Beyond php - it's not (just) about the codeBeyond php - it's not (just) about the code
Beyond php - it's not (just) about the codeWim Godden
 
My app is secure... I think
My app is secure... I thinkMy app is secure... I think
My app is secure... I thinkWim Godden
 
Building interactivity with websockets
Building interactivity with websocketsBuilding interactivity with websockets
Building interactivity with websocketsWim Godden
 
Your app lives on the network - networking for web developers
Your app lives on the network - networking for web developersYour app lives on the network - networking for web developers
Your app lives on the network - networking for web developersWim Godden
 
My app is secure... I think
My app is secure... I thinkMy app is secure... I think
My app is secure... I thinkWim Godden
 
My app is secure... I think
My app is secure... I thinkMy app is secure... I think
My app is secure... I thinkWim Godden
 
The promise of asynchronous php
The promise of asynchronous phpThe promise of asynchronous php
The promise of asynchronous phpWim Godden
 
My app is secure... I think
My app is secure... I thinkMy app is secure... I think
My app is secure... I thinkWim Godden
 
My app is secure... I think
My app is secure... I thinkMy app is secure... I think
My app is secure... I thinkWim Godden
 
Practical git for developers
Practical git for developersPractical git for developers
Practical git for developersWim Godden
 
Beyond php - it's not (just) about the code
Beyond php - it's not (just) about the codeBeyond php - it's not (just) about the code
Beyond php - it's not (just) about the codeWim Godden
 
My app is secure... I think
My app is secure... I thinkMy app is secure... I think
My app is secure... I thinkWim Godden
 
My app is secure... I think
My app is secure... I thinkMy app is secure... I think
My app is secure... I thinkWim Godden
 

Plus de Wim Godden (20)

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

Dernier

"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
 
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
 
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek SchlawackFwdays
 
DevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsDevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsSergiu Bodiu
 
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage Cost
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage CostLeverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage Cost
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage CostZilliz
 
Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 365Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 3652toLead Limited
 
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
 
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
 
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024BookNet Canada
 
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Mark Simos
 
DevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenDevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenHervé Boutemy
 
"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
 
Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024Scott Keck-Warren
 
Powerpoint exploring the locations used in television show Time Clash
Powerpoint exploring the locations used in television show Time ClashPowerpoint exploring the locations used in television show Time Clash
Powerpoint exploring the locations used in television show Time Clashcharlottematthew16
 
Hyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdf
Hyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdfHyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdf
Hyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdfPrecisely
 
How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.Curtis Poe
 
TrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data PrivacyTrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data PrivacyTrustArc
 
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
 
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024BookNet Canada
 

Dernier (20)

"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...
 
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
 
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
 
DevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsDevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platforms
 
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage Cost
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage CostLeverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage Cost
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage Cost
 
Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 365Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 365
 
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
 
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
 
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
 
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
 
DevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenDevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache Maven
 
"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
 
Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024
 
Powerpoint exploring the locations used in television show Time Clash
Powerpoint exploring the locations used in television show Time ClashPowerpoint exploring the locations used in television show Time Clash
Powerpoint exploring the locations used in television show Time Clash
 
Hyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdf
Hyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdfHyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdf
Hyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdf
 
How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.
 
TrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data PrivacyTrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data Privacy
 
E-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptx
E-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptxE-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptx
E-Vehicle_Hacking_by_Parul Sharma_null_owasp.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
 
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
 

The why and how of moving to php 5.4

  • 1. The Why and How of moving to PHP 5.4
  • 2. Who am I ? Wim Godden (@wimgtr) Founder of Cu.be Solutions (http://cu.be) Open Source developer since 1997 Developer of OpenX, PHPCompatibility, Nginx extensions, ... Zend Certified Engineer Zend Framework Certified Engineer MySQL Certified Developer Speaker at PHP and Open Source conferences
  • 3. 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 !
  • 4. Show of hands 3 / 4 5.0 5.1 5.2 5.3 5.4 5.5RC1 6.0 (just kidding)
  • 5. The numbers W3Techs (http://w3techs.com/technologies/details/pl-php/all/all) PHP 4 : 2.7% PHP 5 : 97.2% 5.0 : 0.1% 5.1 : 2.6% 5.2 : 43.5% 5.3 : 49.7% 5.4 : 4.1% 5.5 : < 0.1 %
  • 6. 5.3 quick recap Namespaces () Late static binding Closures Better garbage collection Goto Mysqlnd Performance gain
  • 7. 5.3 – people are not even using it ! 43.5% still on PHP 5.2 No : Symfony 2 Zend Framework 2 Other frameworks that need namespaces Problematic for developers
  • 8. PHP 5.4 – what's changed ? New features Performance and memory usage Improved consistency Some things removed
  • 9. Exciting new things – short array syntax $yourItems = array('a', 'b', 'c', 'd'); $yourItems = ['a', 'b', 'c', 'd']; $yourItems = ['a' => 5, 'b' => 3];
  • 10. Exciting new things – function array dereferencing function getCars() { return array( 'Mini', 'Smart', 'Volvo', 'BMW' ); } $cars = getCars(); echo $cars[1]; function getCars() { return [ 'Mini', 'Smart', 'Volvo', 'BMW' ]; } echo getCars()[1];
  • 11. Exciting new things – Traits Reuse methods across classes Classes have no common parent
  • 12. Traits - example Log output : abcd trait Logger { public function log($data) { echo "Log output : " . $data; } } class SomeClass { use Logger; } $someObject = new SomeClass(); $someObject->log('abcd');
  • 13. Traits - example class SomeClass { public function log($data) { echo "Log output : " . $data; } } $someObject = new SomeClass(); $someObject->log('abcd');
  • 14. Traits – careful ! trait Logger { private $foo; } class SomeClass { private $foo; use Logger; } will throw E_STRICT !
  • 15. Exciting new things – Webserver PHP 5.4 has a built-in webserver Development only ! Handles requests sequentially Ideal for quick testing Ideal for unit testing of webservices
  • 16. Webserver – how to /var/www/php54test/html> php -S localhost:8000 PHP 5.4.15 Development Server started at Sat May 2 00:41:12 2013 Listening on http://localhost:8000 Document root is /var/www/php54test/html Press Ctrl-C to quit. /var/www/php54test/html> php -S localhost:8000 -t /var/www/other-path/html PHP 5.4.15 Development Server started at Sat May 2 00:41:12 2013 Listening on http://localhost:8000 Document root is /var/www/other-path/html Press Ctrl-C to quit. /var/www/php54test/html> php -S localhost:8000 bootstrap.php PHP 5.4.15 Development Server started at Sat May 2 00:41:12 2013 Listening on http://localhost:8000 Document root is /var/www/php54test/html Press Ctrl-C to quit.
  • 17. Exciting new things – SessionHandler New session handling class Groups all methods for session handling : close() destroy() gc() open() read() write()
  • 18. SessionHandler class MySessionHandler extends SessionHandler { public function read($session_id) { // Get the session data } public function write($session_id, $session_data) { // Set the session data } ... } $handler = new MySessionHandler(); session_set_save_handler($handler, true); session_start();
  • 19. Exciting new things – more session stuff File upload extension → file upload registers in session → readable through AJAX calls New function session_status() Return values : PHP_SESSION_ACTIVE / PHP_SESSION_NONE
  • 20. Performance and memory usage Performance : 10 – 30% How ? Core optimizations New internal caches (functions, constants, …) Better (un)serialization Inlining often-used code paths … Reduced memory usage : up to 50% ! Big impact on large frameworks Even bigger impact on codebases such as Drupal
  • 21. What else is new ? (1/3) Binary notation Decimal : 123 Octal : 0173 Hex : 0x7B Binary : 0b1111011 Class member access on object instantiation `$fooObj = new Foo(); echo $fooObj->bar(); echo (new Foo)->bar();
  • 22. What else is new ? (2/3) class Cat { private $meows; function __construct($meows) { $this->meows = $meows; } function __invoke() { return str_repeat('Meow!', $this->meows); } } $furbal = new Cat(5); echo $furbal(); // Outputs: Meow!Meow!Meow!Meow!Meow! Magic method __invoke() :
  • 23. What else is new ? (3/3) class someClass { private $someProperty; function __construct($value) { $this->someProperty = $value; } public function showMeTheMoney() { return function() { echo '$' . $this->someProperty; }; } } $obj = new someClass(5000);; $func = $obj->showMeTheMoney(); $func(); // Outputs: $5000 $objA = new someClass(5000); $objB = new someClass(10000); $func = $objA->showMeTheMoney(); $func(); // Outputs: $5000 $func = $func->bindTo($objB); $func(); // Outputs: $10000 5.3 : 5.4 :
  • 24. Other changes Error handling : 5.3 : Parse error: syntax error, unexpected T_STRING, expecting '{' in index.php on line 1 5.4 : Parse error: syntax error, unexpected 'bar' (T_STRING), expecting '{' in index.php on line 1 Array to string conversion : 5.3 : Array 5.4 : Note: Array to string conversion in test.php on line 8 <?= always works (even with short_tags off) Default charset = UTF8 class foo bar $var = array(); echo $var;
  • 25. Time to remove ! register_globals magic_quotes safe_mode Removed : Still working : break $var; break 2; continue $var; continue 3; session_register() session_unregister() session_is_registered() → use $_SESSION
  • 26. More stuff removed Timezone guessing → date.timezone in php.ini sqlite extension → use sqlite3 New reserved keywords : trait insteadof callable
  • 28. Upgrade : yes / no Yes No Using removed extensions x Using removed functions x Need extra performance / reduced memory x Really need new feature x No unit tests x No package available (.rpm, .deb, ...) x
  • 29. Postponing upgrades End-Of-Life In the past : we'll see Now : minor release + 2 = out → EOL 5.5 = OUT → 5.3 = EOL (soon !) 5.6 = OUT → 5.4 = EOL (next year !) Critical security patches : 1 year No bugfixes Framework support Developer motivation
  • 30. So you want to upgrade... Option 1 : run your unit tests Option 2 : visit each page (good luck !) + check error_log Option 3 : automate it !
  • 31. Back in 2010... PHP Architect @ Belgian Railways 8 years of legacy code 40+ different developers 40+ projects Challenge : migrate all projects from PHP 5.2.4 (on Solaris) to PHP 5.3.x (on Linux)
  • 32. The idea Automate it How ? → Use the CI environment Which tool ? → PHP_CodeSniffer
  • 33. PHP_CodeSniffer Detect 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
  • 35. PHPCompatibility New 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.1, 5.2, 5.3, 5.4 and 5.5
  • 36. PHPCompatibility – making it work Via GIT : git clone git://github.com/wimg/PHPCompatibility.git PHPCompatibility Download from Github : http://github.com/wimg/PHPCompatibility Install in <pear_dir>/PHP/CodeSniffer/Standards Run : phpcs --standard=PHPCompatibility <path>
  • 37. Important notes Large directories → can be slow ! Use --extensions=php,phtml No point scanning .js files Test PHP 5.4 compatibility → need PHP 5.4 on the system Static analysis Doesn't run code Can not detect every single incompatibility Provides filename and line number
  • 38. The result Zend Framework 1.7 app PHP 5.2 : working fine PHP 5.3 : fail ! function goto() No 100% detection 95% automation = lots of time saved !
  • 41. Contact Twitter @wimgtr Web http://techblog.wimgodden.be Slides http://www.slideshare.net/wimg E-mail wim.godden@cu.be Please... Rate my talk : http://joind.in/8643
  • 42. Thanks ! Please... Rate my talk : http://joind.in/8643

Notes de l'éditeur

  1. part 2 look at difficulties you might encounter in upgrading. I&apos;ll provide solutions not a magician can&apos;t solve everything ;-)
  2. 5.3.3 = Debian Squeezy = 12% Wait a second... that means people aren&apos;t even on 5.3 ? And there was 3 year gap between the release of 5.2 and 5.3, so 5.3 brought a lot of cool things.