In this talk I'll present some of the new features of PHP 7. I will present the scalar type and return type declarations, the spaceship and null coalescing operators, the anonymous classes, the new Error exception, the security features, etc. Moreover, I will present some benchmarks and use cases of PHP 7 regarding the huge performance improvement.
3. PHPPHP
PHP: Hypertext Preprocessor
The most popular server-side language: PHP is used by
82.3% of all the websites (source: )
Used by Facebook, Wikipedia, Yahoo, Etsy, Flickr,
Digg, etc
21 years of usage, since 1995
Full OOP support since PHP 5
w3techs.com
7. PHPDEADLINESPHPDEADLINES
Version 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
8. PHP7INANUTSHELLPHP7INANUTSHELL
Great performance (thanks to )
Return/Scalar Type Declarations
Cryptographic secure pseudo-random number
generator (CSPRNG)
Anonymous Classes
Combined Comparison (Spaceship) Operator
Null coalescing operator
New Error hierarchy
PHPNG
9. PERFORMANCEPERFORMANCE
, PHP Next GenerationPHPNG
Project by Dmitry Stogov ( )Zend
New data structure management in the PHP engine
Great performance improvement!
12. PHP 7 is also faster than !Python 3
WORDPRESSWORDPRESS
13. CASESTUDIESCASESTUDIES
Badoo saved one million dollars switching to PHP 7
( )
Tumblr reduced the latency and CPU load by half
moving to PHP 7 ( )
Dailymotion handles twice more traffic with same
infrastructure switching to PHP 7 ( )
source
source
source
16. CSPRNGCSPRNG
Cryptographically 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
17. ANONYMOUSCLASSESANONYMOUSCLASSES
/* 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
18. SPACESHIPOPERATORSPACESHIPOPERATOR
A <=> B
0 if A == B, 1 if A > B, -1 if A < B
echo 1 <=> 1; // 0
echo 1 <=> 2; // -1
echo 2 <=> 1; // 1
echo "a" <=> "a"; // 0
echo "a" <=> "b"; // -1
echo "b" <=> "a"; // 1
19. NULLCOALESCINGNULLCOALESCING
?? 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';
22. PHP7.1PHP7.1
Nullable types
Void return types
Deprecation of Mcrypt ext
Support of in OpenSSL
Support class constant visibility
Iterable pseudo-type
...
Authenticated Encryption
Check the at php.netPHP 7.1 new features
23. 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