U() return different things

If I write this in the config.php:

echo u();

I get this

http://localhost

If I write it in a plugin file I get this:

http://localhost/my-domain

The last one is correct. Can you confirm that you get the same thing on a localhost environment? What’s the reason for this behaviour? Is it a bug?