IntroductionEvery single expression in PHP has one of the following built-in types depending on its value:
PHP is a dynamically typed language, which means that by default there is no need to specify the type of a variable, as this will be determined at runtime. However, it is possible to statically type some aspect of the language via the use of type declarations. Different types that are supported by PHP's type system can be found at the type system page. Types restrict the kind of operations that can be performed on them. However, if an expression/variable is used in an operation which its type does not support, PHP will attempt to type juggle the value into a type that supports the operation. This process depends on the context in which the value is used. For more information, see the section on Type Juggling. Tip
The type comparison tables may also be useful, as various examples of comparison between values of different types are present.
To check the value and type of an
expression,
use the var_dump function.
To retrieve the type of an
expression,
use the get_debug_type function.
However, to check if an expression is of a certain type use the
Output of the above example in PHP 8: bool string int(16)
|