In PHP, is_real() was an old alias of is_float() that checked whether a value is a floating point number. It was deprecated in PHP 7.4 and removed completely in PHP 8.0.
If you call is_real() on PHP 8 or later, you get a fatal error because the function no longer exists. The fix is easy: replace every is_real() with is_float(), which does the same job. This page teaches the replacement and shows how it behaves.
Syntax
Call is_real() with the values you need. Start with this line.
PHP
$ok = is_float($value); // use is_float(), not is_real()
Call
What it does
is_real(1.5)
Removed. On PHP 8.0 or later this causes a fatal error: Call to undefined function is_real().
is_float(1.5)
Returns true. This is the correct replacement for is_real().
is_float(10)
Returns false because 10 is an integer, not a float.
is_real() was deprecated in PHP 7.4 and removed in PHP 8.0. The replacement is is_float(). The alias is_double() still works, but is_float() is the recommended name.
Library declarations
PHP
is_real(mixed $value): bool // removed in PHP 8.0, use is_float()
Parameters
Parameter
Description
value
Required. The value you want to check. In the replacement is_float(), it can be of any type.
Return Value
Return Value
Description
bool
In old PHP versions it returned true for floats. On PHP 8.0 or later the function does not exist, so use is_float(), which returns true for floats and false for everything else.
PHP Examples
Example 1 — The Replacement: is_float()
Use is_float() wherever old code used is_real(). Test a decimal, a float zero and an integer.
'1. 5' is a string. The quotes make it text, so the result is false.
1e3 is a float literal. Scientific notation always creates a float, even though it equals 1000.
10 / 4 gives 2. 5. The answer has a decimal part, so it is a float.
10 / 5 gives exactly 2. PHP returns an int when a division has no remainder, so the result is false.
Example 3 — Migrating Old Code and History
Check on PHP 8 that is_real() is gone and is_float() works. Older code from PHP 7 and earlier used is_real().
PHP
<?php
// PHP 7 and earlier: is_real($price)
// PHP 8 and later: is_float($price)
$price = 19.99;
echo function_exists('is_real') ? 'is_real exists' : 'is_real is gone', PHP_EOL;
echo function_exists('is_float') ? 'is_float exists' : 'is_float is missing', PHP_EOL;
echo is_float($price) ? 'Price is a float' : 'Price is not a float', PHP_EOL;
Output
is_real is gone
is_float exists
Price is a float
How It Works
The comments show the history. Old code used is_real(), and new code uses is_float().
function_exists() tests for a function by name. On PHP 8 it reports that is_real() is gone.
is_float() is still there. It is the permanent, supported name for this check.
The price 19. 99 is a float. So the last line prints Price is a float using the new function.
Frequently Asked Questions
is_real() was an alias of is_float(). PHP deprecated it in version 7.4 and removed it in PHP 8.0, so calling it on a modern version causes a fatal error.
Use is_float(). It checks the same thing, and it works in every PHP version, old and new. You can replace is_real( with is_float( directly.
The name was confusing, because PHP has no 'real' type, only float. Removing the extra aliases made the language more consistent.
Yes. is_double() is still an alias of is_float() and works in PHP 8. Even so, is_float() is the name you should prefer in new code.
Search all your files for is_real( and replace each match with is_float(. Running the code on PHP 7.4 also shows a deprecation notice for each call, which helps you find them.