PHP 7.3 is already bet3 and we will get the final version shortly after Sinterklaas.
A wide range of new features are already available for testing, including the relaxed syntax for Heredocs, the final comma in function calls, and a crowd of smaller increments.
We’ll review those evolutions, check the incompatibilities, and try to find the in PHP code.
Finally, we’ll present the RFC process that leads to new features : we can start to discover PHP 7.4 together!
6. IMPROVED GARBAGE COLLECTOR
// 20M very many objects
ms GC No GC
php54 16343.75 14306.16
php55 10654.09 6405.13
php56 10113.73 6341.04
php70 2737.26 1963.01
php71 2781.83 1881.48
php72 2281.21 1822.88
php73 2277.11 1733.06
php74 2113.07 1602.64
• 10% slower when
deactivated
• No gain for small
scripts
• More objects,
more gain
• Most app won't use GC
8. IMPROVED GARBAGE COLLECTOR
// Some objects (2000)
ms GC No GC
php54 138.82 46.74
php55 90.47 41.35
php56 104.42 50.87
php70 105.29 47.42
php71 185.17 95.66
php72 75.31 72.98
php73 76.07 32.29
php74 70.76 37.39
• 10% slower when
deactivated
• No gain for small
scripts
• More objects,
more gain
• Most app won't use GC
11. • Tabulations or spaces
• Don't mix them!
RELAXED HEREDOC/NOWDOC
<?php
class foo {
public $bar = <<<EOT
bar
EOT;
}
" bar"
12. • Trailing comma
• Just like for arrays
• The last element may be empty
• Only applies to the last element
• Valid of methods and functions
• Targets long diffs with your VCS
TRAILING COMMA
foo(
$foo,
$bar,
$baz,
);
13. NO MORE CASE INSENSITIVE
CONSTANTS
namespace {
define('NSFOO', 42, true);
// Case insensitive constant
}
namespace Test {
use const NSFOO;
var_dump(FOO); // OK
var_dump(foo); // Warning
}
14. NO MORE CASE INSENSITIVE
CONSTANTS
Case-insensitive constants are deprecated. The
correct casing for this constant is "%s
define(): Declaration of case-insensitive
constants is deprecated
• New errors
15. NO MORE CASE INSENSITIVE
CONSTANTS
• Conventions are to declare and use constant in
UPPER CASE
• Constants are more and more defined with const, as
class constant, and not with define()
• null, true, false will be keywords in PHP 8
• __FILE__, __LINE__, … Stay case insensitive
• Only functions are case insensitive now…
17. NEW SQLITE3
• Version 3.24
• Support for UPSERT
• UPSERT = INSERT or UPDATE
• An UPSERT is an ordinary INSERT statement that is
followed by the special ON CONFLICT clause
shown above.
• REPLACE = INSERT or OVERWRITE
18. NEW PCRE VERSION : 2.0!
• PHP 7.2 uses PCRE1
• PHP 7.3 uses PCRE2
• Lots of new features, little incompatibilities
• Options X and S are no more
• Plus de vérifications à la compilation
20. CONTINUE IS FOR LOOPS
<?php
while ($foo) {
switch ($bar) {
case "baz":
continue; // In PHP: Behaves like "break;"
// In C: Behaves like "continue 2;"
}
}
?>
`"continue" targeting switch is equivalent to
"break". Did you mean to use "continue 2"?`
21. JSON_ENCODE RAISE
EXCEPTIONS
• json_encode/json_decode may return NULL , false,
empty string
• How to differentiate between error and valid
result?
• New option : JSON_THROW_ON_ERROR, with its
associate try{ } catch
• A new beginning…
25. HRTIME
• HRTIME is a monotonus timer
• Measures time intervals
• No impact from calendar, like microtime() :
day light saving time, leap seconds…
• It is very precise
• More than microtime()
• Same API from microtime()
26. SAME SITE COOKIE
• setcookie
• setrawcookie
• session_set_cookie_params
• session_get_cookie_params
void session_set_cookie_params ( int $lifetime
[, array $options ] )
Set-Cookie: key=value; path=/; domain=example.org;
HttpOnly; SameSite=Lax
29. REMOVED FEATURES
• image2wbmp
• but imagefromstring() supports webp
• undocumented mbstring() alias
• No more function assert()
• Search in a string with integers
30. FIRST KEY IN AN ARRAY
// usage of an associative array
$array = ['a' => 1, 'b' => 2, 'c' => 3];
31. LAST KEY IN AN ARRAY
// usage of an associative array
$array = ['a' => 1, 'b' => 2, 'c' => 3];
$firstKey = array_keys($array)[0];
$lastKey = array_keys($array)[count($array) - 1];