2

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.

5
  • 4
    The first comment about typecasting was posted 13 years ago, which gives you a hint. This also means that, unless you're just interested in PHP history, you shouldn't care about the actual answer. If the version you actually use is that old, you should really consider an upgrade. Commented Aug 1, 2016 at 23:33
  • @MainMa Some programmers have told me that (int)$var is a weird new feature and that intval($var) or settype($var, 'int') is much better. Commented Aug 2, 2016 at 0:49
  • @CJDennis stackoverflow.com/questions/1912599/… Commented Aug 2, 2016 at 5:47
  • @CJDennis And your idea is to prove them wrong by saying that this feature is old? Commented Aug 2, 2016 at 14:04
  • @VincentSavard Pretty much. If this feature's been around for over 16 years and has stable and non-surprising behaviour (unlike intval()) why would you avoid its use? Commented Aug 2, 2016 at 23:56

1 Answer 1

5

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.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.