migrating to php7

32
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

Upload: richard-prillwitz

Post on 20-Mar-2017

174 views

Category:

Software


0 download

TRANSCRIPT

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

MIGRATING TO PHP7Moving from PHP5.3 to PHP7.0

RICHARD PRILLWITZPHP and JavaScript developer

Refined Labs GmbH

REFINED LABS GMBHFounded 2007

Munich-based

About 30 employees

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

AGENDAWhy upgrading?Getting startedProblems and pitfallsTestingAdvantagesFuture development

WHY UPGRADE OUR APPLICATION?

Mature, monolithic enterprise application

Lots of data to collect, filter and analyze

predates Unit-Testing

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/...

PROBLEMS AND PITFALLS

1REMOVED EXTENSION

MYSQLPHP5

$myEscapedString = mysql_escape_string($myString);

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

2EXTENDED EXCEPTION HANDLING

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

JSON_ENCODE$inf = 3/0;

$nan = 0/0;

$myArray = array(

$inf,

$nan

);

var_dump(json_encode($myArray));

PHP5string(13) "[false,false]"

PHP7bool(false)

3CODE EVALUATION

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

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

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

4SIGNATURE CHANGE

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"

);

TESTING OUR APPLICATION

TESTING SETUP

Testing was scheduled for about two months

ADVANTAGES

PERFORMANCE

FUTURE DEVELOPMENT

NULL COALESCING OPERATORPHP5

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

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

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

SPACESHIP OPERATORPHP5

if ($a == $b)

return 0;

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

PHP7return $a <=> $b;

RETURN TYPE DECLARATIONSfunction getMyArray() : array

return $this­>myArray;

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

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

Questions?