Top Banner
Version November 2014 November 2015 May 2016 PHP 5.3 14.85% 9.90% 2.43% PHP 5.4 28.61% 22.09% 7.64% PHP 5.5 48.87% 50.68% 29.56% PHP 5.6 7.67% 22.09% 39.67% PHP 7.0 - 1.17% 20.24% Source: seld.be
32

Migrating to php7

Mar 20, 2017

Download

Software

Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: Migrating to php7

Version November 2014 November 2015 May 2016

PHP 5.3 14.85% 9.90% 2.43%

PHP 5.4 28.61% 22.09% 7.64%

PHP 5.5 48.87% 50.68% 29.56%

PHP 5.6 7.67% 22.09% 39.67%

PHP 7.0 - 1.17% 20.24%

Source: seld.be

Page 2: Migrating to php7

MIGRATING TO PHP7Moving from PHP5.3 to PHP7.0

Page 3: Migrating to php7

RICHARD PRILLWITZPHP and JavaScript developer

Refined Labs GmbH

Page 4: Migrating to php7

REFINED LABS GMBHFounded 2007

Munich-based

About 30 employees

Page 5: Migrating to php7

Centralised analysis of marketing budgetsCross-Channel-Tracking and Customer JourneyOptimizing marketing budget based on individualattribution modelsAutomatically optimise SEM- & RTB-Budgets via Cross-Channel-Bid Management

Page 6: Migrating to php7
Page 7: Migrating to php7

AGENDAWhy upgrading?Getting startedProblems and pitfallsTestingAdvantagesFuture development

Page 8: Migrating to php7

WHY UPGRADE OUR APPLICATION?

Page 9: Migrating to php7

Mature, monolithic enterprise application

Lots of data to collect, filter and analyze

predates Unit-Testing

Page 10: Migrating to php7

GETTING STARTEDSwitch the PHP-Version on my dev machine

:~$ sudo a2dismod php5 && sudo a2enmod php7.0 && sudo service apache2 restart

Reload the applicationPHP Fatal error: Uncaught Error: Call to undefined function mysql_escape_string() in /home/richard/...

Page 11: Migrating to php7

PROBLEMS AND PITFALLS

Page 12: Migrating to php7

1REMOVED EXTENSION

Page 13: Migrating to php7

MYSQLPHP5

$myEscapedString = mysql_escape_string($myString);

PHP7$myEscapedString = mysqli_real_escape_string($dbLink, $myString);

Page 14: Migrating to php7

2EXTENDED EXCEPTION HANDLING

Page 15: Migrating to php7

DIVIDE BY ZEROvar_dump(3/0);

var_dump(0/0);

var_dump(0%0);

PHP5PHP Warning: Division by zero

bool(false)

PHP Warning: Division by zero

bool(false)

PHP Warning: Division by zero

bool(false)

PHP7PHP Warning: Division by zero

float(INF)

PHP Warning: Division by zero

float(NAN)

PHP Fatal error: Uncaught DivisionByZeroError: Modulo by zero

Page 16: Migrating to php7

JSON_ENCODE$inf = 3/0;

$nan = 0/0;

$myArray = array(

$inf,

$nan

);

var_dump(json_encode($myArray));

PHP5string(13) "[false,false]"

PHP7bool(false)

Page 17: Migrating to php7

3CODE EVALUATION

Page 18: Migrating to php7

VARIABLE INTERPOLATION$obj­>$properties['name']

PHP5$obj­>$properties['name']

PHP7$obj­>$properties['name']

Page 19: Migrating to php7

4SIGNATURE CHANGE

Page 20: Migrating to php7

SESSION_SET_SAVE_HANDLERPHP5.3

function emptyFunction()

session_set_save_handler(

"emptyFunction",

"emptyFunction",

"emptyFunction",

"emptyFunction",

"emptyFunction",

"emptyFunction"

);

PHP7function emptyFunction()return true;

session_set_save_handler(

"emptyFunction",

"emptyFunction",

"emptyFunction",

"emptyFunction",

"emptyFunction",

"emptyFunction"

);

Page 21: Migrating to php7

TESTING OUR APPLICATION

Page 22: Migrating to php7

TESTING SETUP

Testing was scheduled for about two months

Page 23: Migrating to php7
Page 24: Migrating to php7

ADVANTAGES

Page 25: Migrating to php7

PERFORMANCE

Page 26: Migrating to php7

FUTURE DEVELOPMENT

Page 27: Migrating to php7

NULL COALESCING OPERATORPHP5

$myVar = isset($_GET['attributeName']) ? $_GET['attributeName'] : 'defaultValue';

PHP7$myVar = $_GET['attributeName'] ?? 'defaultValue';

$myVar = $_GET['attributeName'] ?? $_GET['fallbackAttributeName'] ?? 'defaultValue';

Page 28: Migrating to php7

SPACESHIP OPERATORPHP5

if ($a == $b)

return 0;

return ($a < $b) ? ­1 : 1;

PHP7return $a <=> $b;

Page 29: Migrating to php7

RETURN TYPE DECLARATIONSfunction getMyArray() : array

return $this­>myArray;

Page 30: Migrating to php7

SCALAR TYPE HINTINGfunction getNumber(int $intNumber) : int

return $intNumber;

var_dump(getNumber(3)); // int(3)

var_dump(getNumber("5")); // int(5)

var_dump(getNumber(2.87)); // int(2)

var_dump(getNumber(false)); // int(0)

var_dump(getNumber(true)); // int(1)

var_dump(getNumber("foo")); // PHP Fatal error

Page 31: Migrating to php7

CONCLUSIONUpgrading to PHP7 is not that hardPHP7 might be a huge boost in performanceCleaner and more stable codeBut......it will not solve all your problems

Page 32: Migrating to php7

Questions?