What's new in PHP 7.3

Ian Littman / @iansltx

SunshinePHP 2019 Uncon

https://ian.im/73sun19

PHP 7.3 is out!

WARNING: PHP < 7.1 is EOL

Upgrade if you haven't already

because Rasmus explains this much better

BeOS support dropped

it works more posix-y now

  • You can now indent closing label, and the runtime will remove that level of indentation from all lines in the string (great for quoting SQL statements without looking weird!)
  • You can now put things after the closing label on the same line
  • WARNING: If you have heredocs that contain the closing label, fix them before upgrading!

 

End result: heredoc/nowdoc are just as useful and way less ugly.

$arr = ['foo' => ['bar' => 'baz']];
['foo' => &$foo] = $arr;
$foo = ['baz' => 'qux'];
print_r($arr); // ['foo' => ['baz' => 'qux']];

 

proof on 3v4l

Other New Core(ish) Features

  • You can now call instanceof on a literal (always false)
  • CompileError (extends ParseError) handles a few things that used to fatal
  • Trailing commas are now allowed in function/method calls (for cleaner diffs, similar to trailing commas in arrays)
  • If linked against libargon2 >= 20161029, supports Argon2i/Argon2id password hash formats
  • You can now tell json_decode() to throw if a decode fails (JSON_THROW_ON_ERROR)
  • More syslog configs
  • var_export() now does something useful with \stdClass

Other New Core(ish) Features #2

  • debug_zval_dump() dedupe on recursive arrays
  • array_push() + array_unshift() can be called with a single operator (useful when calling by unpacking an array)
  • FPM now implements getallheaders()
  • FILTER_VALIDATE_FLOAT supports specifying a thousands separator
  • FILTER_SANITIZE_ADD_SLASHES replaces FILTER_SANITIZE_MAGIC_QUOTES
  • PCRE now uses PCRE2 under the hood
  • Can now pass an options array to setcookie() as 3rd param, as well as first param in session_set_cookie_params()

New functions!

  • array_key_first(), array_key_last() (does not affect pointer)
  • hrtime() // high-resolution monotonic timer
  • is_countable()
  • net_get_interfaces()
  • fpm_get_status() // who's gonna build the first UI for this?
  • DateTime::createFromImmutable()
  • openssl_pkey_derive()
  • Various GMP, intl, LDAP, socket methods

Extension features/improvements

  • FPM logging improvements
    • Configurable line length
    • Fixes log line wrapping issues
    • Experimental logging without extra buffering
  • LDAP extension now supports LDAP Controls
  • MySQL now properly returns fractional seconds in times for both mysqli and PDO
  • Passing through a bunch of cURL constants
  • SimpleXML uses int or float when casting text to a math operation, rather than just using int all the time

BCMath improvements

  • bcscale() now returns the current scale if called with no arguments
  • Consistently uses PHP error handling now
  • bcmul() and bcpow() no longer sometimes drop decimal zeroes

MBString improvements

  • Full case-mapping and case-folding (may change string length)
  • Unicode 11 support
  • Strings > 2GB are now supported
  • Much better performance, particularly for case conversions
  • mb_ereg_* now supports named captures

Cleanup/BC Breaks

  • See previous heredoc/nowdoc warning
  • Warning when using "continue" in a switch (which behaves identically to "break")
  • Numeric strings will no longer be cast to numbers when calling offsetGet on an object implementing ArrayAccess ($foo['123'] will now call offsetGet('123') rather than offsetGet(123) )
  • If you were using assigning by reference to split static property assignment between parent and child classes, that no longer works
  • Cleanup around references return by array/prop access
  • You can't unpack arguments from a Traversable returning non-integer array keys

Cleanup/BC Breaks #2

  • ext_skel is now (completely re)written in PHP
  • Automatic conversion exceptions for e.g. DateTime no longer populate error_get_last()
  • TypeError and Reflection now use "int" and "bool" rather than "integer" and "boolean"
  • compact() on an undefined variable now genrates a Notice
  • getimagesize() etc.: image/x-ms-bmp -> image/bmp
  • stream_socket_get_name() now raps IPv6 addresses in []
  • IMAP/POP3/NNTP SSH/RSH login turned off by default
  • SPL's autoloader now stops on the first exception rather than trying to load everything and chaining exceptions

Deprecations

  • Defining case-insensitive constants (via third param in define()); using constants case-insensitively is already deprecated
  • Calling assert() inside a namespace (due to engine weirdness)
  • Searching strings for a non-string (ASCII codepoint) needle
  • Streaming strip-tags
  • FILTER_FLAG_SCHEME_REQUIRED, FILTER_FLAG_HOST_REQUIRED (use FILTER_VALIDATE_URL)
  • image2wbmp()
  • Various mbstring aliases

Thanks!