Why are global variables not used in WordPress?
WordPress already caches these things in the object cache/memory so it doesn’t have to fetch it multiple times in the same request, you don’t need to store the result and reuse, WP does that already out of the box. It’s very likely your code is running slower as a result of this micro-optimisation, not faster!
Is it safe to use Globals in WordPress core?
Someone else (a plugin maybe) might use globals with the same name, ruining your code, or you ruining its depending on initialization order. WordPress core has way way way much to much use of globals.
When to use Global$ Post and other global variables?
The $post global could be used in all sorts of ways. Whether or not it should be used depends on each circumstance. However, as I understand it, the main intended purpose of the $post global is its use in theme template files.
How to avoid making an object a global?
Basically this is an object that contain all of your globals in an organized way. To avoid making an instance of this object a global (you want ont one instance otherwise you recompute the values) you might want to use a singleton pattern (some people argue it is a bad idea, YMMV)
Why is it bad to use global variables in HTML?
You should just generate the HTML as and when you need it and it would run just as fast, perhaps even a tiny bit faster. This is micro-optimisation. Don’t use global variables, as simple as that. Because the use of globals makes it harder to maintain the software in the long term.
How to avoid making an object a global variable?
To avoid making an instance of this object a global (you want ont one instance otherwise you recompute the values) you might want to use a singleton pattern (some people argue it is a bad idea, YMMV) I don’t like to access an object attribute directly, so in my code it will warpe some more