title: Wordpress register_activation_hook() + global variables + class: cannot redeclare
body: <p>I'm writing my first wordpress plugin and I'm trying to create a function to be called when the plugin is activated.</p>
  <p>Currently it looks like this:</p>
  <pre class="lang-php prettyprint-override"><code>class ThumbsUp {
  
  ...
  
  }
  
  global $thumbs;
  function thumbs_install() {
      //global $thumbs;
      $thumbs = new ThumbsUp();    /* Line 160 */
      $thumbs-&gt;installThumbsUp();
  }                                /* Line 162 */
  
  // When plugin is activated -&gt; install.
  register_activation_hook(__FILE__,'thumbs_install');
  </code></pre>
  <p>But when I activate the plugin I get the following error:</p>
  <blockquote>
  <p>Plugin could not be activated because it triggered a fatal error.</p>
  <p><strong>Fatal error</strong>: Cannot redeclare <code>thumbs_install()</code> (previously declared in <code>/dev/site/wp-content/plugins/thumbs-up/thumbs-up.php:160</code>) in <code>/dev/site/wp-content/plugins/thumbs-up/thumbs-up.php</code> on line 162</p>
  </blockquote>
  <p>I've googled and looked and it's talked about as a variable scope issue but I can't find any examples of the answer and my php is not strong enough to translate the discussion into code.</p>
  <p>Here's <a href="http://lists.automattic.com/pipermail/wp-hackers/2008-December/022934.html" rel="nofollow noreferrer">the solution described by John Blackbourn</a> in the <a href="http://lists.automattic.com/mailman/listinfo/wp-hackers" rel="nofollow noreferrer">WP-hackers ML</a>:</p>
  <blockquote>
  <p>Any global variables that you want to reference inside the function that is called by <code>register_activation_hook()</code> must be explicitly declared as global inside the main body of the plugin (ie. <em>outside</em> of this function). The plugin file is <code>include()</code>-ed inside another function at the point where it is activated unlike at others times when the plugin file is simply <code>include()</code>-ed. Phew. Bit of an odd one to get your head around but there we go.</p>
  </blockquote>
  <p>I thought I had done what is described but I still get the error.  I've also tried every other combination of where I could possibly put the global <code>$thumbs</code>...</p>