src/Tools/Generator.php
private function castToType(string $value, string $type)
    {
        $casts = [
            'integer' => 'intval',
            'number' => 'floatval',
            'float' => 'floatval',
            'boolean' => 'boolval',
        ];

        // First, we handle booleans. We can't use a regular cast,
        //because PHP considers string 'false' as true.
        if ($value == 'false' && $type == 'boolean') {
            return false;
        }

        if (isset($casts[$type])) {
            return $casts[$type]($value);
        }

        return $value;
    }
private function castToType(string $value, string $type)
    {
        $casts = [
            'integer' => 'intval',
            'number' => 'floatval',
            'float' => 'floatval',
            'boolean' => 'boolval',
        ];

        // First, we handle booleans. We can't use a regular cast,
        //because PHP considers string 'false' as true.
        if ($value == 'false' && $type == 'boolean') {
            return false;
        }

        if (isset($casts[$type])) {
            return $casts[$type]($value);
        }

        return $value;
    }
private function castToType ( string $ value , string $ type ) { $ casts = [ 'integer' => 'intval' , 'number' => 'floatval' , 'float' => 'floatval' , 'boolean' => 'boolval' , ] ; // First, we handle booleans. We can't use a regular cast, //because PHP considers string 'false' as true. if ( $ value == 'false' && $ type == 'boolean' ) { return false ; } if ( isset ( $ casts [ $ type ] ) ) { return $ casts [ $ type ] ( $ value ) ; } return $ value ; }
Cast a value from a string to a specified type.

@param string $value
@param string $type

@return mixed
Cast a value from a string to a specified type .