Skip to content

Upgrading to PHP 8.5: what actually breaks

PHP 8.4 leaves active support on 31 December 2026, and 8.5 is the upgrade. This is the list of small conveniences 8.5 deprecates and the behaviours it changes, with the replacement for each, measured on 8.5.13.

PHP 8.4 has been the current release since November 2024, and its active support ends on 31 December 2026. After that date it still receives security fixes, but no ordinary bug fixes, so a site that wants its reported problems patched has to be on 8.5. That release has been out since 20 November 2025, and the current build is 8.5.13.

The good news is that the upgrade is small. PHP 8.5 removes almost nothing and, unlike 8.0, it does not rewrite the language underneath you. What it does is deprecate a long list of small conveniences and change the behaviour of a handful of others, and nearly all of it happens quietly. Everything below comes from measurements on PHP 8.5.13 on my test server, with PHP 8.4.27 beside it for comparison, so the messages are the ones you will see.

Find out what your own code hits first

Finding most of this work takes two commands, and neither of them is part of the upgrade. They are preparation: a lint and a text search that you run to see which lines will change behaviour, so you know what to edit before you switch versions. The first is the lint you already run, with one flag added. PHP’s command-line default leaves deprecations out of error_reporting, so a plain php -l calls all six files of my demo tree clean while the same run with the level raised reports five deprecations:

PHP decides every one of those while it reads the file, before a single line runs. That is exactly why the lint is the right tool here: a cast and a backtick have no function name to search for.

The second command is a plain text search rather than a PHP tool. grep knows nothing about PHP; it finds the names of functions that 8.5 now deprecates, which is how you locate those calls in your own code. On the same six files:

Neither command says anything about the deprecations that only appear when a line actually runs. For those, run one request with the level raised and read the output:

What stops or warns

This is the short half, and it holds the changes that make code do something other than what it did. None of them remove a function, so none of them announce themselves as a missing call.

What the code does What happens now
class_alias('ArrayObject', 'array') Fatal error: Cannot use "array" as a class alias as it is reserved
new mysqli(), then ->__construct() on it again Error: Cannot call constructor twice
new ArrayObject($enumCase) InvalidArgumentException: Enums are not compatible with ArrayObject
destructuring a number, as in [$a, $b] = 42; Warning: Cannot use int as array, and both variables become null
casting a float too large for an int, as in (int) 1.0e20 Warning: The float 1.0E+20 is not representable as an int, cast occurred
casting NAN to an int or a string two warnings, then 0 and "NAN"
$xml->xpath('count(//a)'), where the expression is not a node set a warning, and false instead of an empty array
ini_set('disable_classes', 'ArrayObject') the setting is gone, and ini_set() returns false

Check the class-alias row if you use class_alias() to make short names: “array” and “callable” were never types you could alias honestly, and 8.5 stops pretending. Two more changes in this section used to work. An enum case can no longer be the backing store of an ArrayObject. And a loose comparison between an enum case and a boolean now follows (bool) in every case, which is silent, and which only shows up when the other side of the comparison is a variable rather than a literal.

The deprecations the compiler catches

PHP reports this whole group while it reads the file, so the lint above is what finds them, and a php -l without the raised level reports nothing at all. First come four cast spellings that were never canonical:

The replacement is a one-word edit in every case, and the two forms have always meant the same thing, so there is nothing to re-test:

Next comes a case label that ends with a semicolon instead of a colon. Its message names the character to change:

The backtick operator goes the same way. It was always only a shorter spelling of shell_exec(), and PHP has deprecated the spelling rather than the act:

One detail about this group matters if you write your own error handler. Because PHP decides these at compile time, their messages arrive before any code runs. In a file that also has runtime deprecations, the compiler’s lines come first, in file order, so a handler that expects lines in the order the code runs will look wrong here.

Objects that now free themselves

The largest group of deprecations is one idea repeated across extensions. A handle that used to need an explicit close now frees itself when the variable goes out of scope, so the close call has turned into a no-op with a notice attached.

Deprecated call What to do
curl_close(), curl_share_close() delete the line, the handle frees itself
finfo_close() delete the line too
imagedestroy() and this one
xml_parser_free() and this one
finfo_buffer($f, $data, $flags, $context) drop the fourth argument, PHP ignores it
$store->attach(), ->contains(), ->detach() offsetSet(), offsetExists(), offsetUnset()
mysqli_execute() mysqli_stmt_execute()
socket_set_timeout() stream_set_timeout()
ReflectionMethod::setAccessible(), ReflectionProperty::setAccessible() delete it, it has had no effect since 8.1
openssl_pkey_derive($key, $key, $length) drop the length argument, the curve decides it

Measured, each message names its own reason, and the reasons are not the same:

For that group the fix is deletion, not a replacement. The call has done nothing since PHP 8.0, so the notice asks you to remove a no-op rather than fix behaviour. SplObjectStorage behaves differently: those three methods still do their job and only the names have moved.

Constants and DSNs that moved

The next set of changes is a replacement value in each case, rather than a deleted line.

Deprecated Use instead
PDO::MYSQL_ATTR_INIT_COMMAND and the other driver-prefixed constants Pdo\Mysql::ATTR_INIT_COMMAND, and the matching namespaced class for each driver
new PDO('uri:/etc/dsn') a plain DSN string, not one read from a file or a URL
DATE_RFC7231, DateTimeInterface::RFC7231 a format string, or RFC1123 with GMT set explicitly
MHASH_MD5 and the other MHASH_* constants hash() with 'md5', plus its own algorithm names
chr(300), ord('ab') use chr($n % 256), and ord($s[0]) for the byte you meant
$row[null], array_key_exists(null, $row) $row[''], and array_key_exists('', $row)

The array-offset row is the easiest to overlook, because $row[null] and $row[''] still find the same key today. That is exactly what makes the change easy to postpone. Measured, the two messages that carry a version read differently from the pattern above:

Settings, methods and operators that moved

The remaining changes each need a setting or a call replaced. None of them stop the page, and several write nothing to the log at all.

Deprecated Use instead
the intl.error_level setting intl.use_exceptions, or check the return value yourself
the register_argc_argv setting read $_GET or $_SERVER['QUERY_STRING'], with register_argc_argv=0
the report_memleaks setting drop it from the configuration
incrementing a non-numeric string, as in $label++ str_increment($label)
__sleep(), __wakeup() __serialize(), __unserialize()
$http_response_header http_get_last_response_headers()
readdir(null), rewinddir(null), closedir(null) pass the directory handle you mean

Some of these print nothing at all, which is why a scan earns its place even when nothing looks broken. Setting intl.error_level, register_argc_argv or report_memleaks at runtime prints nothing. PHP also writes no message when a class declares __sleep() or __wakeup(), and none when you read $http_response_header. For all of those, the manual carries the note and nothing else does. The advice for __sleep() and __wakeup() is to add the two newer methods beside the old ones, so a class stays readable by both. Incrementing a non-numeric string does warn, and it names the replacement:

readdir(null) needs an argument rather than a deletion: passing null always meant “use the last opened directory”, and 8.5 asks you to name the handle instead.

What PHP 8.5 adds

The other half of the release is what you gain by upgrading, and the headline is the pipe operator, |>. It takes the value on its left and passes it as the single argument of the callable on its right, which turns a nest of calls into a readable chain:

Two smaller additions are worth adopting in the same pass. A function whose return value matters can carry the #[\NoDiscard] attribute, and a caller that really does mean to ignore it says so with a (void) cast:

The second is casts inside a constant expression, which removes a class of one-off constants people wrote to work around the old restriction. A constant can now settle its value at compile time:

More of what 8.5 adds

Three more features change how you write a modern class. A property can carry #[\Override] now, so a name that was meant to override a parent is checked instead of quietly becoming a new member. Measured, a property with that attribute and no matching parent property stops at compile time:

A constant can carry an attribute as well, including #[\Deprecated], which is the first time a constant can announce its own replacement. And clone has become a function, which lets it take a set of values to replace during the copy:

The new values may only touch a property the current scope can write, so calling that form on a readonly property from outside the class raises Error: Cannot modify protected(set) readonly property Config::$host from global scope. The copy still leaves the original untouched, which is what makes the form useful for a settings object.

Two additions are about seeing what went wrong. A fatal error now carries a backtrace, so an exhausted memory limit or a timeout shows the calls that led to it instead of a single file and line. And a validation filter can be told to throw, by passing FILTER_THROW_ON_FAILURE, rather than hand back a value you then have to check:

The last two are worth a mention for completeness. A uri extension is now always present, and it adds Uri\Rfc3986\Uri and Uri\WhatWg\Url, two classes that parse a URL the way a browser does. And intl gains IntlListFormatter, which joins words with the right conjunction for a locale:

On a hosting account

On a shared plan the version is a per-domain setting in the control panel, and switching back is immediate and loses nothing. So the safe order is the one the commands at the top already describe: copy the site, run the lint and the grep over the copy, run one request with the level raised and read what it prints, fix what it found, and only then move the domain.

Two things to check before you start. The extensions your code leans on have to be present on 8.5, and php -m prints the list for whichever binary you point it at. Since 8.5, PHP builds Opcache into the binary and always loads it, and it no longer ships an opcache.so at all. A zend_extension=opcache.so line left in your php.ini now fails to load, and it should come out:

Fix the deprecations first. They cost nothing today, and they become the fatal errors of the release after this one. PHP deprecated each() in 7.2 and removed it in 8.0. It deprecated mcrypt in 7.1 and removed it in 7.2. Each deprecation buys you a window like that, and nothing tells you when it closes.

Sources

Leave a reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.