the new features of php 7

23
THE NEW FEATURES OF PHP 7 THE NEW FEATURES OF PHP 7 by - Senior Software Engineer , a Rogue Wave Company (USA) , Milan, 25th Nov. 2016 Enrico Zimuel @ezimuel Zend Technologies Codemotion

Upload: zend-by-rogue-wave-software

Post on 15-Jan-2017

84 views

Category:

Software


1 download

TRANSCRIPT

THE NEW FEATURES OF PHP 7THE NEW FEATURES OF PHP 7by -

Senior Software Engineer, a Rogue Wave Company (USA)

, Milan, 25th Nov. 2016

Enrico Zimuel @ezimuel

Zend Technologies

Codemotion

PHPPHPPHP: Hypertext PreprocessorThe most popular server-side language: PHP is used by82.3% of all the websites (source: )Used by Facebook, Wikipedia, Yahoo, Etsy, Flickr,Digg, etc21 years of usage, since 1995Full OOP support since PHP 5

w3techs.com

PHP ECOSYSTEMPHP ECOSYSTEMCMS: , , , etcE-commerce: , , , etcCRM: , , , , etcWiki: , , , etcFramework: , , , etc

Drupal Wordpress JoomlaMagento OpenCart PrestaShop

CiviCRM SugarCRM Vtiger ZurmoDokuWiki MediaWiki PmWiki

Laravel Symfony Zend Framework

PHP 7PHP 7Released: 3 December 2015

Last major was , 13 July 2004 (11 years!)PHP 5

Last release is (10 Nov 2016)7.0.13

PHP 6 ?PHP 6 ?Unicode support at the core language level

Not released, project is abandoned

PHP DEADLINESPHP DEADLINESVersion Release Supported until

5.3 30 June 2009 14 August 2014

5.4 1 March 2012 3 September 2015

5.5 20 June 2013 21 July 2016

5.6 28 August 2014 31 December 2018

7.0 3 December 2015 3 December 2018

7.1 December 2016? 3 years

PHP7 IN A NUTSHELLPHP7 IN A NUTSHELLGreat performance (thanks to )Return/Scalar Type DeclarationsCryptographic secure pseudo-random numbergenerator (CSPRNG)Anonymous ClassesCombined Comparison (Spaceship) OperatorNull coalescing operatorNew Error hierarchy

PHPNG

PERFORMANCEPERFORMANCE, PHP Next GenerationPHPNG

Project by Dmitry Stogov ( )Zend

New data structure management in the PHP engine

Great performance improvement!

BENCHMARKBENCHMARK$a = [];for ($i = 0; $i < 1000000; $i++) { $a[$i] = ["hello"];}echo memory_get_usage(true);

PHP 5.6 PHP 7

Memory Usage 428 MB 33 MB

Execution time 0.49 sec 0.06 sec

OTHER LANGUAGESOTHER LANGUAGES

PHP 7 is also faster than !Python 3

PHP 7 is also faster than !Python 3

WORDPRESSWORDPRESS

CASE STUDIESCASE STUDIESBadoo saved one million dollars switching to PHP 7( )Tumblr reduced the latency and CPU load by halfmoving to PHP 7 ( )Dailymotion handles twice more traffic with sameinfrastructure switching to PHP 7 ( )

source

source

source

RETURN TYPE DECLARATIONSRETURN TYPE DECLARATIONSfunction foo(): array { return [];}

function bar(): DateTime { return null; // invalid}

More information: PHP documentation

SCALAR TYPE DECLARATIONSSCALAR TYPE DECLARATIONSdeclare(strict_types=1);

function sendHttpStatus(int $statusCode, string $message) { header('HTTP/1.0 ' .$statusCode. ' ' .$message);}sendHttpStatus(404, "File Not Found"); // oksendHttpStatus("403", "OK"); // fatal error

function add(float $a, float $b): float { return $a + $b;}add(1, 2); // float(3)

More information: PHP documentation

CSPRNGCSPRNGCryptographically secure pseudo-random number

generators

// generates a random number between 1 and 100$num = random_int(1,100);

// generates a random string of 1 Kb$bytes = random_bytes(1024);

More information: PHP documentation

ANONYMOUS CLASSESANONYMOUS CLASSES/* return an anonymous class */return new class($controller) implements Page { public function __construct($controller) { /* ... */ } /* ... */};

class Foo {}$child = new class extends Foo {};var_dump($child instanceof Foo); // true

More information: PHP documentation

SPACESHIP OPERATORSPACESHIP OPERATORA <=> B

0 if A == B, 1 if A > B, -1 if A < B

echo 1 <=> 1; // 0echo 1 <=> 2; // -1echo 2 <=> 1; // 1

echo "a" <=> "a"; // 0echo "a" <=> "b"; // -1echo "b" <=> "a"; // 1

NULL COALESCINGNULL COALESCING?? operator

// Fetches the value of $_GET['user'] and returns 'nobody'// if it does not exist.$username = $_GET['user'] ?? 'nobody';// This is equivalent to:$username = isset($_GET['user']) ? $_GET['user'] : 'nobody';

// Coalescing can be chained$username = $_GET['user'] ?? $_POST['user'] ?? 'nobody';

NEW ERROR HIERARCHYNEW ERROR HIERARCHYThrowable: Error, Exception

function call_method($obj) { $obj->method();}

try { call_method(null); // oops!} catch (Error $e) { printf ("Error: %s\n", $e->getMessage());} catch (Exception $e) { printf ("Exception: %s\n", $e->getMessage());}

More information: PHP documentation

MUCH MORE...MUCH MORE...Consistent 64-bit supportFix list() behavior inconsistencyFiltered unserialize()Group use declarationsClosure::call()Expectations...

Check the at php.netPHP 7 new features

PHP 7.1PHP 7.1Nullable typesVoid return typesDeprecation of Mcrypt extSupport of in OpenSSLSupport class constant visibilityIterable pseudo-type...

Authenticated Encryption

Check the at php.netPHP 7.1 new features

THANKS!THANKS!Contact me: enrico.zimuel [at] roguewave.com

Blog and web site: www.zimuel.it

Follow me: @ezimuel

This work is licensed under a.

I used to make this presentation.Creative Commons Attribution-ShareAlike 3.0 Unported License

reveal.js