The PHP 8.6 upgrade checklist says "fix the deprecations", and for most of this batch that is a find-and-replace you can do in one commit. is_integer() becomes is_int(), doubleval() becomes floatval(), and nothing about your application changes.
spl_object_hash() is the one that needs thought. It turns up in identity maps, dedupe loops and debugging helpers, and the replacement changes a guarantee that some of that code quietly relies on.
Swap the free aliases first#
Four of the 8.6 deprecations are aliases that have pointed at the same C function for twenty years. Replacing them is safe, has no behavioural difference, and gets most of the deprecation noise out of your log in one pass.
// Deprecated in PHP 8.6 // Use instead
is_integer($value); is_int($value);
is_long($value); is_int($value);
is_double($value); is_float($value);
doubleval($value); floatval($value); // or (float) $value
Each has its own RFC entry in the PHP 8.6 deprecations, and each emits E_DEPRECATED at call time — so a noisy test suite is the fastest way to find them. In a Laravel app they hide mostly in old validation helpers and in array-shaping code copied from a Stack Overflow answer in 2014:
// Before
if (is_integer($row['quantity']) && is_double($row['price'])) {
$total += $row['quantity'] * doubleval($row['price']);
}
// After
if (is_int($row['quantity']) && is_float($row['price'])) {
$total += $row['quantity'] * (float) $row['price'];
}
Don't hand-edit these. They are exactly what Rector's php86 set is for, and the last step of this article runs the whole lot in one command.
Replace spl_object_hash() with spl_object_id()#
spl_object_hash() returns a 32-character string derived from the object's internal handle. spl_object_id() returns that handle directly as an int. Anywhere you used the hash purely as an array key, the id is a drop-in replacement that allocates less and hashes faster.
// Before — a visited set during a recursive serialiser
final class GraphWalker
{
/** @var array<string, true> */
private array $visited = [];
public function walk(object $node): void
{
$key = spl_object_hash($node); // 32-char string key
if (isset($this->visited[$key])) {
return;
}
$this->visited[$key] = true;
// ...
}
}
// After — identical semantics, int keys
final class GraphWalker
{
/** @var array<int, true> */
private array $visited = [];
public function walk(object $node): void
{
$key = spl_object_id($node); // int handle
if (isset($this->visited[$key])) {
return;
}
$this->visited[$key] = true;
// ...
}
}
The same applies to deduping a collection of models in an import run, or keeping a per-object scratchpad inside a single service call. If the array lives and dies inside one request, the swap is free.
Check for the id-reuse trap before you ship#
Here is the part the alias comparison hides: neither value is a stable identifier. Both the hash and the id are derived from a slot in PHP's object store, and that slot is handed to the next object once the current one is garbage collected. If your map outlives the objects in it, you can get a collision.
$a = new stdClass();
$idA = spl_object_id($a); // e.g. 1
unset($a); // slot released
$b = new stdClass();
$idB = spl_object_id($b); // 1 again — same handle, different object
var_dump($idA === $idB); // bool(true)
spl_object_hash() behaved exactly the same way; the string just made it look like a UUID, so the bug stayed hidden. Two rules follow:
- Never persist it. A hash or id written to cache, a database column, a queued job payload or a log line that is later matched back to an object is already broken. Use the model key, a ULID, or something you own.
- Hold a reference or accept the reuse. A map keyed by id is only correct while something keeps those objects alive. If your long-running process (Octane, Horizon, a daemon command) keeps the array but drops the objects, you now have stale entries pointing at whatever took the slot.
That second rule is the real reason to care under Octane and FrankenPHP, where a container-scoped service survives thousands of requests and an identity map that leaks is both a memory leak and a correctness bug.
Reach for WeakMap when the map only decorates an object#
If the array exists purely to attach data to an object — a computed value, a flag, a cached relation — the id is the wrong tool entirely. PHP 8.0's WeakMap keys on the object itself and drops the entry when the object is collected, so there is no key to reuse and nothing to clean up.
final class PermissionCache
{
/** @var \WeakMap<\App\Models\User, array<string, bool>> */
private \WeakMap $cache;
public function __construct()
{
$this->cache = new \WeakMap();
}
public function allows(User $user, string $ability): bool
{
$this->cache[$user] ??= [];
return $this->cache[$user][$ability] ??= $user->can($ability);
}
}
No spl_object_id(), no manual eviction, no reuse trap. I now treat a spl_object_id() map as a smell in long-running code: most of them want to be a WeakMap, and the memory-safe object caching patterns are worth reading before you reach for either.
The exception is when you genuinely need the key without the value — a visited set inside one recursive call, say. An int key is fine there, and cheaper.
Move locale sorting to Collator#
strcoll() and the SORT_LOCALE_STRING flag are both deprecated in 8.6. The replacements live in ext-intl: Collator::compare() for the one-off comparison, and Collator::sort(), Collator::asort() or Collator::sortWithSortKeys() for the array case.
// Before — process-global locale, deprecated flag
setlocale(LC_COLLATE, 'en_GB.UTF-8');
sort($names, SORT_LOCALE_STRING);
// After — explicit locale, no global state
$collator = new \Collator('en_GB');
$collator->sort($names); // reindexes, like sort()
$collator->asort($names); // preserves keys, like asort()
This is an upgrade, not just a rename. setlocale() mutates process-wide state, which has always been a hazard in a worker that serves requests for users in different locales — one request changes the collation for every request after it on the same worker. A Collator is an object you build per locale and can cache safely:
/** @var array<string, \Collator> */
private array $collators = [];
public function sortedForUser(User $user, array $names): array
{
$locale = $user->locale ?? 'en_GB';
// One Collator per locale, reused for the life of the worker.
$collator = $this->collators[$locale] ??= new \Collator($locale);
$collator->asort($names);
return $names;
}
If ext-intl isn't in your Docker image yet, add it — Collator needs it, and so does most of the multibyte and formatting work covered in the mb_trim and multibyte string helpers article.
Clear the leftovers: spl_classes, metaphone and mysqli#
Four smaller items round out the list, and each has a one-line answer:
spl_classes()→(new ReflectionExtension('SPL'))->getClassNames(). Almost nobody calls this outside a debug command.metaphone()→ no core replacement.soundex()is not deprecated, but if you are doing real fuzzy name matching, a userland phonetic library (or a trigram index in Postgres) will beat both.mysqli_get_charset()andmysqli_stmt_init()→ only relevant if you have raw mysqli outside Eloquent. Laravel's MySQL driver is PDO, so most apps score a zero here.- Mbregex — the whole
mb_ereg_*family is deprecated because Oniguruma is unmaintained. That one is a genuine migration rather than a rename, and it is covered separately in migrating mb_ereg to PCRE.
// spl_classes() replacement
$splClasses = (new \ReflectionExtension('SPL'))->getClassNames();
Automate the pass with Rector, Pint and PHPStan#
Everything above except the spl_object_hash() judgement call is mechanical, so let the tools do it. Enable the PHP 8.6 set in rector.php:
use Rector\Config\RectorConfig;
return RectorConfig::configure()
->withPaths([__DIR__ . '/app', __DIR__ . '/tests'])
->withPhpSets(php86: true); // renames the deprecated aliases
Then run the sequence, reading the diff rather than trusting it:
vendor/bin/rector process --dry-run # read every change first
vendor/bin/rector process # apply
vendor/bin/pint # normalise formatting
vendor/bin/phpstan analyse # catch the type shifts
composer test # prove nothing moved
Rector will rewrite the aliases and the spl_object_hash() calls. It will not tell you which of those calls was persisting the value — that is the review you do by hand, and rg 'spl_object_(hash|id)' across the codebase is the fastest way to find the ones worth a second look. If you want this as one command alongside your other static analysis, the Duster setup for Pint, PHPStan and Rector wires it together.
Gotchas and edge cases#
Deprecations are not errors — until they are. These all emit E_DEPRECATED in 8.6 and are slated for removal in PHP 9. If your production log level swallows deprecations you will see nothing; if you run tests with error_reporting(E_ALL) and fail on deprecations, you will see everything at once. Do the second.
Vendor code will trip them too. A deprecation raised inside vendor/ is not yours to fix with Rector. Check whether the package has a release supporting 8.6 before you suppress anything, and keep the suppression scoped to that path rather than silencing the level globally.
spl_object_id() is an int, so beware loose comparisons. A map previously keyed by a 32-char hex string now has int keys. Code doing array_keys($map) and passing those keys somewhere typed as string will start failing under declare(strict_types=1) — which is the behaviour you want, but it is a second diff to review. The knock-on effects are the same ones described in what declare(strict_types=1) actually changes.
Collator is not a drop-in for sort() semantics. Collator::sort() returns bool and sorts by reference, same as sort(), but the ordering for accented characters will genuinely differ from SORT_LOCALE_STRING on some platforms. If a test asserts an exact sorted order, expect it to need updating — the new order is the more correct one.
Wrapping Up#
Do this one early in the 8.6 migration. It is mostly mechanical, it clears the deprecation noise that otherwise hides the real problems, and the only judgement call is whether any spl_object_hash() value was escaping the request — which is a bug worth finding on its own.
Run the PHP 8.6 upgrade checklist next for the breaking changes that need more than a rename, and if Rector is new to your pipeline, automating Laravel upgrades with Rector covers the config and CI setup properly.
FAQ#
What replaces spl_object_hash() in PHP 8.6?
spl_object_id() is the documented replacement, and it is what the deprecation RFC points at. It returns the object's internal handle as an int instead of a 32-character string, so it works directly as an array key and uses less memory. The only difference that matters is cosmetic — unless your code was treating the hash as a stable identifier, in which case it was already broken.
Is spl_object_id() unique across an entire request?
Only while the object is alive. The id is a slot in PHP's object store, and once an object is garbage collected that slot is reused by the next object created. Two different objects in the same request can therefore have the same id, so a map that outlives its keys can silently return the wrong entry. spl_object_hash() had exactly the same behaviour.
Why are is_integer() and is_long() deprecated?
They have always been plain aliases of is_int(), as is_double() is of is_float() and doubleval() is of floatval(). PHP 8.6 deprecates the duplicates so there is one obvious spelling for each check, and because the "long"/"double" naming reflects C types that stopped being meaningful to PHP developers long ago. There is no behavioural change: replace the name and move on.
What should I use instead of SORT_LOCALE_STRING?
Use ext-intl's Collator. Collator::sort() replaces sort($array, SORT_LOCALE_STRING), Collator::asort() preserves keys, and Collator::sortWithSortKeys() is faster for large arrays you sort repeatedly. For single comparisons, Collator::compare() replaces strcoll(). The collator also takes the locale explicitly, which avoids the setlocale() global-state problem in long-running workers.
Can Rector fix PHP 8.6 deprecations automatically?
Yes for the renames. Enabling the php86 set with ->withPhpSets(php86: true) rewrites the deprecated aliases and the spl_object_hash() calls across your codebase, and --dry-run shows you the diff before anything is written. What it cannot do is judge intent: it will happily convert a spl_object_hash() that was being persisted somewhere, so review those call sites by hand before merging.