Slide 1

Slide 1 text

WHAT'S NEW IN PHP 7? PHP LOST COUNT - WHAT HAPPENED TO PHP 6? WHO CARES? PHP 7! 7!! @mattiasgeniar PHP 7 Release Party @ Nucleus

Slide 2

Slide 2 text

WHAT'S THIS TALK ABOUT? History: PHP 6 New features in PHP 7 Removed features Q & A Some Nucleus 'announcements' Raf e?

Slide 3

Slide 3 text

WHO AM I? Mattias Geniar System Engineer / Support Lead @ Former dev, mostly Ops now Strong advocate of #DevOps Blogger at and Nucleus.be ma.ttias.be www.nucleus.be

Slide 4

Slide 4 text

CRON.WEEKLY Weekly newsletter with linux & open source news, tools, tips & projects www.cronweekly.com

Slide 5

Slide 5 text

SPECIAL SHOUT-OUT Big thanks to Tom Schuermans ( ) for his help in the presentation & organisation! @tschuermans

Slide 6

Slide 6 text

HISTORY: LOSING TRACK, WHAT ABOUT PHP 6? Development started in 2015 ... and died in 2010 "The Great Unicode Release" Besides unicode, all features went to 5.x release 5.3 was pretty much PHP 6 without unicode

Slide 7

Slide 7 text

PHP 7: WHAT'S NEW? Scalar type declarations Return type declarations null coalesce operator Spaceship operator Arrays in constant de ne()'s Anonymous classes

Slide 8

Slide 8 text

PHP 7: WHAT'S NEW? (CONT'D) Unicode codepoint escape syntax & IntlChar Filtered (whitelisted) unserialize() Grouped namespacing in use Session improvements

Slide 9

Slide 9 text

SCALAR TYPE DECLARATIONS // Coercive mode function sumOfInts(int ...$ints) { return array_sum($ints); } var_dump(sumOfInts(2, '3', 4.1)); // Outputs int(9); New in PHP 7: string, integer, oat, boolean

Slide 10

Slide 10 text

strict mode // Strict mode declare(strict_types=1); function sumOfInts(int ...$ints) { return array_sum($ints); } var_dump(sumOfInts(2, '3', 4.1)); // Outputs PHP Fatal error: Uncaught TypeError: Argument 2 passed to sumOf must be of the type integer, string given, called in test2.php o line 10 and defined in test2.php:5 Stack trace: #0 test2.php(10): sumOfInts(2, '3', 4.1) #1 {main}

Slide 11

Slide 11 text

RETURN TYPE DECLARATIONS function sum($a, $b): float { return $a + $b; } // Result is a float, even with integer input var_dump(sum(1, 2)); float(3)

Slide 12

Slide 12 text

strict mode declare(strict_types=1); function sum($a, $b): int { return $a + $b; } // Result is a fatal error, float vs integer mismatch var_dump(sum(1, 2.5)); PHP Fatal error: Uncaught TypeError: Return value of sum() must be of the type integer, float returned in test3.php: Stack trace: #0 test3.php(11): sum(1, 2.5) #1 {main}

Slide 13

Slide 13 text

'STRICT MODE' GOTCHAS Enabled/disabled per le, not a php.ini setting applies to function calls, not to the functions declarations (so: if de ned in test.php, all function calls made from test.php have strict typing) Integers are allowed for functions requiring oat

Slide 14

Slide 14 text

NULL COALESCE OPERATOR = 7 $username = $_GET['user'] ?? 'nobody'; // Chained: $_GET, then $_POST, then 'nobody' $username = $_GET['user'] ?? $_POST['user'] ?? 'nobody'

Slide 15

Slide 15 text

SPACESHIP OPERATOR

Slide 16

Slide 16 text

SPACESHIP OPERATOR It returns -1, 0 or 1 when $a is respectively less than, equal to, or greater than $b echo 1 <=> 1; // 0 echo 1 <=> 2; // -1 echo 2 <=> 1; // 1 // Example: usort callbacks // Note: also works on characters usort($data, function ($left, $right) { return $left[1] <=> $right[1]; });

Slide 17

Slide 17 text

ARRAYS IN CONSTANTS

Slide 18

Slide 18 text

ANONYMOUS CLASSES setLogger(new class implements Logger { public function log(string $msg) { echo $msg; } });

Slide 19

Slide 19 text

ANONYMOUS FUNCTIONS (PHP >= 5.3)

Slide 20

Slide 20 text

UNICODE = 7 ª

Slide 21

Slide 21 text

YOU KNOW WHAT THAT MEANS ...

Slide 22

Slide 22 text

FILTERED / WHITELISTED UNSERIALIZE() false ]); // converts all objects into __PHP_Incomplete_Class object // except those of MyClass and MyClass2 $data = unserialize($foo, [ "allowed_classes" => ["MyClass", "MyClass2"] ]);

Slide 23

Slide 23 text

GROUPED USE DECLARATIONS

Slide 24

Slide 24 text

SESSION IMPROVEMENTS session_start() accepts array of options (undocumented) option "read_and_close": stops session blocking! // PHP 7: session_start([ 'read_and_close' => true, ]); // PHP <= 7 session_write_close();

Slide 25

Slide 25 text

REMOVED FEATURES & EXTENSIONS IN PHP 7 plain 'mysql' extension removed (mysqli / pdo only from now on) php.ini: removed "#" comments, only ";" from now on Removed asp_tags: <% ... %> Finally removed ereg() (deprecated since 5.3) preg_replace() no longer supports "\e"

Slide 26

Slide 26 text

REMOVED FEATURES & EXTENSIONS IN PHP 7 (PART DEUX) Finally removed set_magic_quotes_runtime() (deprecated since 5.3) Removed always_populate_raw_post_data in php.ini

Slide 27

Slide 27 text

UNIFORM VARIABLE SYNTAX $array['item']; --> $object->{$array['item']}; // PHP >= 7 $object->$array['item']; --> ${object->$array}['item'];

Slide 28

Slide 28 text

DATE.TIMEZONE WARNINGS REMOVED default still UTC = 7 (nothing)

Slide 29

Slide 29 text

SAPI TRIVIA How many ways are there to run PHP? PHP 5.6: 20+ PHP 7.0: 6 PHP 7.0 removed: aolserver, apache, apache_hooks, apache2 lter, caudium, continuity isapi, milter, nsapi, phttpd, pi3web, roxen, thttpd, tux, webjames PHP 7.0 supports: embedded, apache2 module, fpm, cgi, cli, litespeed

Slide 30

Slide 30 text

PERFORMANCE 7 VS 5.6 Test sites http://phpseven.lin5.nucleus.be/wordpress/ http://php ve.lin5.nucleus.be/wordpress/ Basic Wordpress, no tweaks or con g changes $ ab -c 1 -n 100 http://site/wordpress PHP 7.0: 12.9req/s (75ms per request) PHP 5.6: 8.9 req/s (120ms per request) PHP 5.5: 2.5 req/s (450ms per request)

Slide 31

Slide 31 text

PERFORMANCE OF PHP 7 IN ONE SLIDE

Slide 32

Slide 32 text

PERFORMANCE OF PHP 7 IN ONE SLIDE 6x faster than PHP 5.5 1.6 faster than PHP 5.6 Your mileage may vary

Slide 33

Slide 33 text

Q & A (hold on, we've got more coming)

Slide 34

Slide 34 text

SOME NUCLEUS ANNOUNCEMENTS 100gr of PHP 7 for everyone! (conveniently packed in a 16GB USB disk with the PHP 7 source code on it)

Slide 35

Slide 35 text

SOME NUCLEUS ANNOUNCEMENTS As of today, PHP 7 support on our shared hosting! Let's merge this feature live!

Slide 36

Slide 36 text

SOME NUCLEUS ANNOUNCEMENTS Free PHP 7 shared hosting for everyone here! (give me your e-mail address, I'll hook you up)

Slide 37

Slide 37 text

PHP 7 ELEPHPANT RAFFLE Time to bribe Mike!

Slide 38

Slide 38 text

THANKS! Contact via @mattiasgeniar or via [email protected]