What Is New in PHP 7.3
PHP 7.3 delivers incremental improvements focused on developer convenience, modern syntax, and tighter security. It's a refinement release that makes everyday coding a bit smoother without major breaking changes.
| Category | Key Changes |
|---|---|
| New Features | Flexible Heredoc/Nowdoc, Trailing Commas, list() Reference Assignment, is_countable(), array_key_first(), array_key_last() |
| Deprecations | Case-Insensitive Constants, Undocumented MBString Regex, FILTER_FLAG_SCHEME_REQUIRED, image2wbmp() |
| Security | PCRE2 Upgrade, Multiple Encryption Fixes |
| Other Changes | JSON Error Handling, LDAP Controls Support |
What are the new syntax features in PHP 7.3?
This release introduces several syntax tweaks that clean up code. The most noticeable is flexible Heredoc and Nowdoc syntax, which no longer requires the closing tag to be on a line by itself.
Trailing commas in function calls are now allowed. This is great for version control diffs because adding a new parameter doesn't change the previous line. You can also assign references directly from list() or [].
// Flexible Heredoc
$text = <<<END
a
b
c
END;
// Trailing comma
$array = [1, 2, 3,];
// list() reference assignment
list($a, &$b) = $array;
Which new array functions were added?
PHP 7.3 adds three utility functions for common array operations. array_key_first() and array_key_last() fetch the first and last keys of an array without resetting the internal pointer.
The is_countable() function solves a common warning. It checks if a variable is an array or implements Countable, preventing the "count(): Parameter must be an array or an object that implements Countable" error.
$array = ['a' => 1, 'b' => 2, 'c' => 3];
$firstKey = array_key_first($array); // 'a'
$lastKey = array_key_last($array); // 'c'
if (is_countable($maybeArray)) {
$count = count($maybeArray);
}
What has been deprecated?
Several outdated behaviors are now soft-deprecated, meaning they generate warnings. Defining case-insensitive constants is deprecated; all constants are case-sensitive.
Using undocumented regex styles in the Mbstring extension triggers a warning. The FILTER_FLAG_SCHEME_REQUIRED and FILTER_FLAG_HOST_REQUIRED flags for filter_var() are also deprecated. The function image2wbmp() is replaced by imagewbmp().
// Deprecated: Case-insensitive constant
define('CONSTANT', 1, true);
// Deprecated: Undocumented mbstring regex
mb_ereg_match('(?xyz)[a-z]*', 'abc');
How did JSON handling improve?
JSON error handling got a significant upgrade. The new JSON_THROW_ON_ERROR option for json_encode() and json_decode() makes error handling much cleaner.
Instead of checking the return value for null and then calling json_last_error(), you can wrap your calls in a try/catch block. This brings JSON parsing in line with modern exception-based practices.
try {
$data = json_decode($json, true, 512, JSON_THROW_ON_ERROR);
} catch (JsonException $e) {
echo $e->getMessage();
}
What are the security updates?
The underlying PCRE library was upgraded to PCRE2, which provides better security and support for modern regex standards. This change is mostly internal but ensures the engine remains robust.
Multiple fixes were applied to the OpenSSL and Cryptography extensions. These patches address edge cases and potential vulnerabilities in encryption handling, making the crypto functions more reliable.
FAQ
Should I upgrade my production application to PHP 7.3 immediately?
Yes, but test first. PHP 7.3 is a minor release with mostly additive changes and deprecation warnings. The upgrade path from 7.2 is generally smooth, but you should check for any deprecated features you might be using.
What is the most useful new feature for everyday coding?
Trailing commas in function calls are a small but impactful quality-of-life improvement. It makes editing multi-line arrays and function arguments cleaner in version control systems like Git.
I keep getting a warning about case-insensitive constants. How do I fix it?
This means you're using the third parameter in a define() call and setting it to true. Remove that parameter and ensure your code uses the correct case for the constant name, as all constants are now strictly case-sensitive.
Does the new JSON exception handling break existing code?
No, it's entirely optional. Your old code that uses json_last_error() will continue to work exactly as before. The new JSON_THROW_ON_ERROR flag is an alternative, better way to handle errors.
Why was the PCRE library upgrade to PCRE2 important?
PCRE2 is the modern, maintained version of the Perl Compatible Regular Expressions library. The upgrade provides security patches, bug fixes, and support for newer regex syntax that wasn't available in the older PCRE library.