Merge "Expand the list of types that can be cast to int"

This commit is contained in:
jenkins-bot 2019-11-10 11:00:36 +00:00 committed by Gerrit Code Review
commit 7ff4b95aec
2 changed files with 12 additions and 2 deletions

View file

@ -440,7 +440,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();
}
/**

View file

@ -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