PHP 7.1 contains new exciting features and improvements that can facilitate the life of many PHP developers. During the talk I will show some of these new features like nullable types, catching of multiple exceptions, the curl HTTP/2 server push support, void return types, Class constant visibility, authenticated encryption in OpenSSL with GCM and CCM modes, and more.
2. ABOUTME
Developer since 1996
Senior Software Engineer at
, a Company
Core team of and
and international speaker
Research Programmer at
Co-founder of (Italy)
Zend Rogue Wave
Apigility ZF
TEDx
Amsterdam University
PUG Torino
4. 7.1BYNUMBERS
376 bug xes
12 new features
13 new functions
36 new global constants
20 backward incompatible changes
2 deprecated features
16 changed functions
7 other changes
17. USINGREFLECTION
$obj = new ReflectionClass("ConstDemo");
foreach ($obj->getReflectionConstants () as $const) {
var_dump($const); // object(ReflectionClassConstant)
var_dump($const->getName());
var_dump($const->getValue());
var_dump($const->isPublic());
var_dump($const->isPrivate());
var_dump($const->isProtected());
}
Re ectionClassConstant is not documented (BUG )#74261
18. MULTIPLECATCH{}
try {
// Some code...
} catch (ExceptionType1 $e) {
// Code to handle the exception
} catch (ExceptionType2 $e) {
// Same code to handle the exception
} catch (Exception $e) {
// ...
}
try {
// Some code...
} catch (ExceptionType1 | ExceptionType2 $e) {
// Code to handle the exception
} catch (Exception $e) {
// ...
}
19. NEGATIVESTRINGOFFSETS
var_dump("abcdef"[-2]); // string(1) "e"
var_dump("abcdef"[-7]); // string(0) "", PHP Notice offset
// strpos
var_dump(strpos("aabbcc", "b", -3)); // int(3)
// get the last character of a string
$last = substr($foo, -1); // before PHP 7.1
$last = $foo[-1];
20. ASYNCSIGNALHANDLING
pcntl_async_signals() has been introduced to enable
asynchronous signal handling without using ticks
pcntl_async_signals(true); // turn on async signals
pcntl_signal(SIGHUP, function($sig) {
echo "SIGHUPn";
});
posix_kill(posix_getpid(), SIGHUP);
21. CLOSUREFROMCALLABLE
class Test
{
public function exposeFunction()
{
return Closure::fromCallable([ $this, 'privateFunction']);
}
private function privateFunction($param)
{
var_dump($param);
}
}
$privFunc = (new Test)->exposeFunction();
var_dump($privFunc); // object(Closure)
$privFunc('some value'); // string(10) "some value"
22. OPENSSLAEAD
Authenticated Encrypt with Associated Data (AEAD)
Support GCM and CCM encryption modes
GCM is 3x faster than CCM. See this benchmark
More info on Authenticated Encryption in PHP 7.1
27. HTTP/2SERVERPUSH
Server push has been added to CURL 7.46+
Use curl_multi_setopt() function with the new
CURLMOPT_PUSHFUNCTION constant
Added CURL_PUSH_OK and CURL_PUSH_DENY to
approve or deny the callback execution
29. EXAMPLE(2)
$active = null;
do {
$status = curl_multi_exec($mh, $active);
do {
$info = curl_multi_info_read( $mh);
if (false !== $info && $info['msg'] == CURLMSG_DONE) {
$handle = $info['handle'];
if ($handle !== null) {
$transfers--; // decrement remaining requests
$body = curl_multi_getcontent( $info['handle']);
curl_multi_remove_handle( $mh, $handle);
curl_close( $handle);
}
}
} while ($info);
} while ($transfers);
curl_multi_close($mh);
30. NEWHASHFUNCTIONS
Added hash_hkdf() function to support HKDF ( )RFC 5869
$key = random_bytes(32);
$salt = random_bytes(16);
$encryptKey = hash_hkdf('sha256', $key, 32, 'encrypt', $salt);
$authKey = hash_hkdf('sha256', $key, 32, 'auth', $salt);
var_dump($encryptKey !== $authKey); // bool(true)
Added SHA3 support (224, 256, 384, and 512)
$hash = hash('sha3-224', 'This is a text');
var_dump($hash);
// string(56)"9209f5869ad03ac11549902b3c83fe8e6b7e1cd1614ab4291587db43"
31. TOSUMMARIZE
Nullable and void return types
Array destructuring
Iterable
Class CONST visibility
Multiple catch {}
Async signal handling
Closure from callable
OpenSSL AEAD
HTTP/2 Server Push
New hash functions
32. THANKS!
Rate this talk at https://joind.in/talk/935fc
Contact me: enrico.zimuel [at] roguewave.com
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