“Non-canonical cast (double) is deprecated” in WordPress: PHP 8.5 explained

By CompatNav · Published · Last reviewed · 2 min read

Short answer

It’s a deprecation notice from PHP 8.5: a plugin or theme converts a value with an old, long spelling of a type, such as (double), (integer), (boolean) or (binary). The code keeps working and gives the same result. PHP 8.5 wants the short names: (float), (int), (bool) and (string). The message itself names the replacement. Update the plugin, or send the message to its developer.

The message, exactly

A shop plugin converts a price and a stock flag with the long names. PHP 8.4 runs it silently; PHP 8.5 adds one notice per cast, each naming the replacement:

wp-content/plugins/simple-shop/price.php

<?php
$price = (double) '19.90';
$in_stock = (boolean) 1;
echo $price, ' ', var_export($in_stock, true), "\n";

Output on PHP 8.4.26

19.9 true

Output on PHP 8.5.11

Deprecated: Non-canonical cast (double) is deprecated, use the (float) cast instead in /var/www/html/wp-content/plugins/simple-shop/price.php on line 2

Deprecated: Non-canonical cast (boolean) is deprecated, use the (bool) cast instead in /var/www/html/wp-content/plugins/simple-shop/price.php on line 3
19.9 true

php.net, in the PHP 8.5 deprecations: “Non-canonical cast names (boolean), (integer), (double), and (binary) have been deprecated, use (bool), (int), (float), and (string) respectively.” (php.net)

The four names and their replacements

Old name (deprecated)Use instead
(double)(float)
(integer)(int)
(boolean)(bool)
(binary)(string)

(real) went earlier: php.net, for PHP 7.4: “The (real) cast is deprecated, use (float) instead.” (php.net) It was removed in PHP 8.0, so code that still uses it doesn’t load on any PHP 8 version.

Is it urgent?

No. The output above is identical on 8.4 and 8.5: 19.9 true. It should be fixed at some point, because a future PHP version is expected to remove the old names, and the notices appear each time the file loads.

Who fixes it

  1. Find the plugin or theme: the folder after wp-content/plugins/ or wp-content/themes/ in the message.
  2. Update it (Dashboard → Updates).
  3. Already on the latest version? Send one full line of the message to its developer.
  4. Keep notices off your pages: the WordPress debug log shows how.

A check that reads code finds every one while your site still runs PHP 8.4:

The other PHP 8.5 changes, including the three that can stop code: WordPress and PHP 8.5.

Key takeaways

  • It’s a deprecation notice from PHP 8.5; the result is exactly the same as before.
  • Four old names are deprecated: (double), (integer), (boolean), (binary).
  • Replacements: (float), (int), (bool), (string); each message names its own.
  • It appears when the file loads, so one old file can add several lines to your log on every request.
  • A check that reads code finds every one before you upgrade.

Frequently asked questions

Is it urgent?

No. The values are the same on PHP 8.4 and 8.5; PHP only adds the notice. A future PHP version is expected to remove the old names.

Does (real) count too?

(real) is older still: it was deprecated in PHP 7.4 and removed in PHP 8.0. Code that still has it doesn’t load on PHP 8 at all.

Is WordPress itself affected?

This notice comes from plugin or theme code. WordPress 6.9 and later are compatible with PHP 8.5.

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.

Get CompatNav on wordpress.org How it works

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.