Expressions And Operators: Casting

Casts in Hack convert values to different types. To assert a type without changing its value, see type assertions.

(float)1; // 1.0
(int)3.14; // 3, rounds towards zero

(bool)0; // false

(string)false; // ""

Casts are only supported for bool, int, float and string. See type conversions to understand what value will be produced.

Was This Page Useful?
Thank You!
Thank You! If you'd like to share more feedback, please file an issue.