PHP Variable Functions

About This Index
This page is the PHP Variable Functions index for the tutorial track. Each row links to a full guide with syntax, examples, and FAQs for one function or language construct that works with variables and types.
Learn how to test types, cast values, check existence, debug and serialize on /php/variable. Use this page when you need the details of one function such as intval(), isset(), or var_dump().
The functions are grouped by job: cast and convert, type tests, existence, inspect and debug, and serialize. If you are not sure where to start, read PHP Variables first.
They are written like functions, but they are part of the PHP language itself. You cannot pass them as callbacks or call them through a variable name.
How to Call a PHP Variable Function
Every function is global—call it directly, with no object and no namespace. One example from each group:
$n = intval("42abc"); // int: 42 (cast and convert)
$ok = is_numeric("1e3"); // bool: true (type test)
$set = isset($user['name']); // bool (existence)
$type = get_debug_type(1.5); // string: "float" (inspect and debug)
$text = serialize([1, 2, 3]); // string (serialize)
var_dump($n); // prints int(42), returns nothing
$copy = print_r([1, 2], true); // true as 2nd argument returns a string
unset($n); // removes the variable PHP Variable Functions Table
All function guides in this PHP tutorial series (37 tutorials in 5 categories). Aliases and the removed is_real() are marked in their rows.
Cast & convert
6 functionsChange a value from one type to another. Each function has a matching cast: (int), (float), (string) and (bool). settype() changes the variable itself.
| Function | Description | Tutorial |
|---|---|---|
boolval() | Convert a value to a boolean. | Try it |
floatval() | Convert a value to a float. | Try it |
doubleval() | Alias of floatval(). | Try it |
intval() | Convert a value to an integer, in any base. | Try it |
strval() | Convert a value to a string. | Try it |
settype() | Change the type of a variable in place. | Try it |
Type tests
17 functionsAsk what type a value has. Every is_* function returns true or false and never changes the value.
| Function | Description | Tutorial |
|---|---|---|
is_array() | Check whether a value is an array. | Try it |
is_bool() | Check whether a value is a boolean. | Try it |
is_callable() | Check whether a value can be called as a function. | Try it |
is_countable() | Check whether a value can be used with count(). | Try it |
is_float() | Check whether a value is a float. | Try it |
is_double() | Alias of is_float(). | Try it |
is_real() | Old alias of is_float(). Removed in PHP 8.0. | Try it |
is_int() | Check whether a value is an integer. | Try it |
is_integer() | Alias of is_int(). | Try it |
is_long() | Alias of is_int(). | Try it |
is_iterable() | Check whether a value can be used in foreach. | Try it |
is_null() | Check whether a value is null. | Try it |
is_numeric() | Check whether a value is a number or a numeric string. | Try it |
is_object() | Check whether a value is an object. | Try it |
is_resource() | Check whether a value is an open resource. | Try it |
is_scalar() | Check whether a value is an int, float, string or bool. | Try it |
is_string() | Check whether a value is a string. | Try it |
Existence
3 functionsDecide whether a variable exists and holds a useful value. These three are language constructs, not real functions, but they are written like functions.
Inspect & debug
9 functionsLook inside a variable. Some functions print the value, some return its type name, and some describe resources or the whole scope.
| Function | Description | Tutorial |
|---|---|---|
gettype() | Get the legacy type name, such as integer or double. | Try it |
get_debug_type() | Get the modern type name, such as int or a class name (PHP 8.0+). | Try it |
var_dump() | Print the type and value of a variable. | Try it |
print_r() | Print a readable form of a variable, or return it as a string. | Try it |
var_export() | Print or return a variable as valid PHP code. | Try it |
debug_zval_dump() | Print a variable together with its internal reference count. | Try it |
get_defined_vars() | Return every variable in the current scope as an array. | Try it |
get_resource_id() | Get the numeric ID of a resource (PHP 8.0+). | Try it |
get_resource_type() | Get the type name of a resource, such as stream. | Try it |
Serialize
2 functionsTurn a value into a string that can be stored, and turn it back. Never unserialize data that you do not trust.
| Function | Description | Tutorial |
|---|---|---|
serialize() | Turn a value into a storable string. | Try it |
unserialize() | Rebuild a value from a serialized string. | Try it |
Aliases and Removals
Several names in this index do the same job. Pick the preferred name and use it throughout your code:
| Alias | Preferred function | Status |
|---|---|---|
doubleval() | floatval() | Alias, still works |
is_double() | is_float() | Alias, still works |
is_integer() | is_int() | Alias, still works |
is_long() | is_int() | Alias, still works |
is_real() | is_float() | Removed in PHP 8.0; calling it is a fatal error |
is_real() was deprecated in PHP 7.4 and removed in PHP 8.0. If you upgrade an old project, replace it with is_float(). The (real) cast was removed at the same time, so use (float).
Frequently Asked Questions
Start with boolval()
Open the next guide—syntax, examples, and FAQs.
6 people found this page helpful
