A sneak peek at PHP 8.4
MergePHP July 2024
Ian Littman
- Thanks to release managers Eric Mann, Calvin Buckley, and Saki Takamachi
- Feature freeze on August 13
- Release targeted for November 21
- More info on the wiki
- Release schedule/support timelines have recently changed
What we'll cover
How do I get it?
- macOS
-
brew tap shivammathur/php
-
brew install php@8.4
-
- Red Hat-based: use Remi's repo
- Inside Docker: e.g. php:8.4.0alpha1-fpm-alpine3.20
- Source code to build yourself is on php.net
WARNING: This is an alpha. Don't deploy this to production.
New Features + Improvements
class User implements Named
{
private bool $isModified = false;
public function __construct(private string $first, private string $last){}
public string $fullName {
// Override the "read" action with arbitrary logic.
get => $this->first . " " . $this->last;
// Override the "write" action with arbitrary logic.
set {
[$this->first, $this->last] = explode(' ', $value, 2);
$this->isModified = true;
}
}
}
- array_find - first value in array for which callback returns true
- array_find_key - first key in array for which callback returns true
- array_all - whether callback returns true for all items
- array_any - whether callback returns true for at least one item
- Polyfill via polyfills/array-find
Date improvements
- ->getMicrosecond()/setMicrosecond()
- ::createFromTimestamp()
- Available on DateTime/DateTimeImmutable
- NOT in DateTimeInterface
Security
- Sodium supports AEGIS-128L/AEGIS256
- tempnam() filenames are now 13 bytes longer
- bcrypt default cost is now 12, up from 10
- OpenSSL Curve25519/Curve448 support (including ed25519)
NumberS!
- Rounding
- bcceil, bcfloor, bcround
- New rounding modes in round() and Intl NumberFormatter::round()
- Slightly better max precision (by one digit)
- BCMath is now faster
- fpow() method for IEEE 754 compliant raising-to-a-power
String manipulation
DOM
Other additions
- new Foo->bar() now works (previously needed to be (new Foo)->bar())
- #[\Deprecated] attribute
- http_(get|clear)_last_response_headers (for e.g. file_get_contents via HTTP)
- feature_list array key in curl_version() response
- request_parse_body() (returns [$looks_like_POST, $looks_like_FILES])
- PHP integer size in phpinfo
- More info in Closure::__debugInfo() (and names tweaked for better visibility)
- PDO driver-specific SQL parsers and driver-specific subclasses
- Various Postgres client improvements (in the PGSQL extension)
- Various Reflection improvements
- SplObjectStorage::seek(): SeekableIterator
- XMLReader/Writer operation on streams
- Various performance improvements
Exceptions/input validation
- dom
- Intl
- mb_*
- pcntl
- SimpleXML
- SplFixedArray out of bounds
- XMLReader/XMLWriter
- XSL
- round() on invalid mode
- xml_set_*_handler()
Resources -> Types
- BCMath numbers (RFC accepted, not yet implemented)
- ODBC connections and results
- SoapClient Url, Sdl (and typemap is now an array)
- Bonus: Clark Notation support
- StreamBucket
- More typed constants
- Date
- Intl
- PDO
- Spl
- Sqlite
- XMLReader
- PHP_DEBUG, PHP_ZTS (now bools)
- JIT is enabled based on a flag rather than buffer size
- PHP will now exit if JIT is enabled and fails to init
- Opcache interned string buffer default is 8x larger
JIT/Opcache
- Core -> PECL
- PHP built-in web server recursively falls back to index.php more aggressively
- PCRE is now updated (changes behavior)
- SimpleXML now doesn't reset the iterator in a few cases
- strcspn() now doesn't bug out when it sees a null byte
- Newer openssl, curl requirements
Other BC Breaks
- Implicitly nullable parameter declarations aka (string $foo = null)
- session_set_save_handler() with callables rather than SessionHandlerInterface
- CURLOPT_BINARYTRANSFER (was a no-op anyway)
- Passing PHP session ID via URL parameter rather than cookie (and URL rewriting to include session IDs)
- DatePeriod::__construct() (use DatePeriod::createFromISO8601String())
- ldap_connect() with more than 2 arguments, ldap_exop() with more than 4
- Escaped question marks in PDO_PGSQL inside dollar-quoted strings
- Various PgSQL methods with omitted row arg (pass null instaed)
- ReflectionMethod::__construct() with one argument
- stream_context_set_option() with two arguments
Deprecations
Thanks! Questions?
- This talk: ian.im/php84amerge
- GitHub: github.com/iansltx
- Fediverse: phpc.social/@ian
- Twitter: @iansltx
A Sneak Peek at PHP 8.4 - MergePHP July 2024
By Ian Littman
A Sneak Peek at PHP 8.4 - MergePHP July 2024
- 76