Let all function nodes return a specific type, which was added as optional feature to DQL functions in 24e9a7c.
This should be done in a way where users are forced to implement getReturnType, because otherwise people will keep returning the values as "string" from their custom dQL when used in scalar context.
Using a Query Hint, we can make this opt-in in ORM 3 and opt-out in ORM 4. Since we have default query hints, users can use this as a global switch and setting. $config->setDefaultQueryHints([Query::FORCE_SCALAR_TYPE_CONVERSION => true]); or FORCE_SCALAR_TYPE_AS_STRINGS => true.