Non-canonical Type Function Aliases are Deprecated in PHP 8.6

Non-canonical Type Function Aliases are Deprecated in PHP 8.6

In PHP, several type functions are available under more than one name. The alternative names carry older type terms which PHP no longer uses elsewhere, such as long for an integer and double for a float. Each alias behaves exactly like the function it points to, so only the name differs. PHP provides the following aliases:

No.Canonical functionAlias
1.is_floatis_double
2.is_intis_long
3.is_intis_integer
4.floatvaldoubleval

Since PHP 8.6, these aliases are deprecated. The change follows the deprecation of non-canonical scalar type casts in PHP 8.5, which removed the same outdated type names from the cast syntax. This means the following code will trigger deprecations:

<?php

$isFloat = is_double(1.5);
$isInt1 = is_long(1);
$isInt2 = is_integer(1);
$float = doubleval('1.5');

Output:

Deprecated: Function is_double() is deprecated since 8.6, use is_float() instead ...
Deprecated: Function is_long() is deprecated since 8.6, use is_int() instead ...
Deprecated: Function is_integer() is deprecated since 8.6, use is_int() instead ...
Deprecated: Function doubleval() is deprecated since 8.6, use floatval() instead ...

Each deprecation is raised at the line which calls the alias, and the message names the function which should be used instead. Both is_long and is_integer point to is_int, so the four aliases map to three canonical functions.

In the previous example, deprecations can be fixed using canonical functions:

<?php

$isFloat = is_float(1.5);
$isInt1 = is_int(1);
$isInt2 = is_int(1);
$float = floatval('1.5');

Leave a Comment

Cancel reply

Your email address will not be published.