Is the php $GLOBALS associative array over written in WordPress with the WordPress $GLOBALS? I have a piece of code that uses $GLOBALS['myvariablename'] to access a global variable. It works in php, but stops working when I bring the code to a WordPress environment.

Is there a way to use $GLOBALS associative array? Or should I absolutely declare variables global before getting them in functions and using them?

Added Later:

My code: http://bharath.lohray.com/sources/redditGetVotes.phps

I am trying to use the reddit API to fetch and display the popularity of my links on my wordpress blog. The global variables are for configuration information - like the reddit user name etc. I have documented my steps in my post here.

  • You shouldn't use $Globals at all, but where and how are you placing this global? – Wyck Oct 6 '13 at 16:58
  • Post your code, please. globals are best avoided if possible, but for what it is worth I have not noticed any real issue with them if you understand how they work. – s_ha_dum Oct 6 '13 at 17:07
  • @s_ha_dum: Updated question. My Code is at bharath.lohray.com/sources/redditGetVotes.phps It is workign for now, but I cannot use $GLOBALS['variableName'] as an associative array. – Lord Loh. Oct 6 '13 at 22:08

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.