The PHP website tells you which versions each function is supported in and often the version a function was first introduced in, but it doesn't do the same for older language features. When was type casting first introduced? i.e. (int)$var
or (string)$var
.
1 Answer
PHP 3.
PHP 3.0 was released in October 2000.[1, scroll bottom]
Code about type casting could be found in one of the earliest php-src commits,[2] which was in 1999. This proves that type casting most likely existed in PHP 3.
PHP 2 docs asked users to use SetType()
or IntVal()
to move the type from double to int,[3] which suggests that PHP 2 didn't have type casting directly.
Therefore it can be deduced that type casting was introduced in PHP 3.
(int)$var
is a weird new feature and thatintval($var)
orsettype($var, 'int')
is much better.intval()
) why would you avoid its use?