diff --git a/includes/parser/AFPData.php b/includes/parser/AFPData.php index 3875eb589..3caac9592 100644 --- a/includes/parser/AFPData.php +++ b/includes/parser/AFPData.php @@ -431,7 +431,13 @@ class AFPData { * @return int|float */ public function toNumber() { - return $this->type === self::DINT ? $this->toInt() : $this->toFloat(); + // Types that can be cast to int + $intLikeTypes = [ + self::DINT, + self::DBOOL, + self::DNULL + ]; + return in_array( $this->type, $intLikeTypes, true ) ? $this->toInt() : $this->toFloat(); } /** diff --git a/tests/parserTests/cast.t b/tests/parserTests/cast.t index dec3d5549..e13803d6e 100644 --- a/tests/parserTests/cast.t +++ b/tests/parserTests/cast.t @@ -10,4 +10,8 @@ float( [false] ) === 1.0 & float( [1,2,3,4,5,6] ) === 6.0 & int([]) === 0 & int( [false] ) === 1 & -int( [1,2,3,4,5,6] ) === 6 +int( [1,2,3,4,5,6] ) === 6 & +true + true === 2 & +null - null === 0 & +true * false === 0 & +163 % true === 0