“Method ReflectionProperty::setAccessible() is deprecated since 8.5”: what it means and the fix
Short answer
It’s a deprecation notice from PHP 8.5: a plugin or theme calls setAccessible(true) before reading a private property or method through PHP’s Reflection API. Since PHP 8.1 that call does nothing: Reflection can read private members anyway. So the code still works, and PHP 8.5 points out the useless call. The fix is to remove it, or, for code that still supports PHP 8.0 and older, to call it only there. Update the plugin, or send the message to its developer.
The message, exactly
An order-tools plugin reads a private total through Reflection, after the traditional setAccessible(true). PHP 8.4 runs it silently; PHP 8.5 gives the same result and adds the notice:
wp-content/plugins/order-tools/order-tools.php
<?php
class Order {
private $total = 99;
}
$property = new ReflectionProperty(Order::class, 'total');
$property->setAccessible(true);
echo 'Total: ', $property->getValue(new Order()), "\n";
Total: 99Deprecated: Method ReflectionProperty::setAccessible() is deprecated since 8.5, as it has no effect since PHP 8.1 in /var/www/html/wp-content/plugins/order-tools/order-tools.php on line 7
Total: 99php.net, in the PHP 8.5 deprecations: “The setAccessible() methods of various Reflection objects have been deprecated, as those no longer have an effect.” (php.net)
What it means
PHP’s Reflection API lets code look inside classes, including private properties. Up to PHP 8.0, reading a private property that way required calling setAccessible(true) first. PHP 8.1 dropped that requirement, which turned the call into a no-op. Code kept calling it, and PHP 8.5 now flags it.
Who fixes it
- Find the plugin or theme: the folder after
wp-content/plugins/orwp-content/themes/in the message. If the path continues into avendor/folder, it’s a library bundled by that plugin. - Update it (Dashboard → Updates).
- Already on the latest version? Send one line of the message to its developer.
- Meanwhile, keep notices off your pages: the WordPress debug log.
Found before you switch
The call is in the code, so a check that reads code finds it while your site still runs PHP 8.4:
All the PHP 8.5 changes, and which of them stop code: WordPress and PHP 8.5.
Key takeaways
- A deprecation notice from PHP 8.5; the code keeps working.
setAccessible()has had no effect since PHP 8.1, and PHP 8.5 says so in the message.- It applies to
ReflectionPropertyandReflectionMethodalike. - Fix: remove the call; keep it only behind a version check if the code supports PHP 8.0 or older.
- A check that reads code finds it while your site runs PHP 8.4.
Frequently asked questions
Which plugins use Reflection?
Code that inspects other classes, for example dependency containers or serialisation libraries, often bundled inside larger plugins. The path in the message shows which plugin, and which bundled library if there is one.
Is it urgent?
No. The call has done nothing since PHP 8.1, and removing it changes nothing on PHP 8.1 and later. Pass it on so it’s gone before a later PHP version removes the method.
The message names a library in a vendor folder. Who fixes it?
The plugin that bundles it. Its developer updates the library or patches the call; editing files under vendor/ yourself is undone by the next plugin update.
Check your own site before you upgrade
CompatNav is a free WordPress plugin. It reads the code of your plugins and themes on your own server and tells you, in plain words, what will break and what will only show notices on the PHP version you choose. It never changes your code. It can’t see problems that only appear while code runs with real data, so a quick check of your site after the upgrade still matters.
Sources
About the code examples: each output is the real output of the code shown, run with the official PHP builds, without a php.ini, with all errors reported and displayed. Only the file path was replaced by a neutral server path.