Support » Fixing WordPress » WP destroys header’s global vars?

  • I’m using WP 2.9.2 and I cant’ understand why global vars defined into header.php are destroyed, once they’re accessed from other .php modules, like functions.php.

    Can someone help?

Viewing 6 replies - 1 through 6 (of 6 total)
  • While trying to debug out the problem…. I have noticed that I’m loading a .php module into the sidebar using ajax asynchronous load; that it is, to achieve this I need to preload into the .php module the following call:

    <?php require_once( '../../../wp-load.php' );

    otherwise the ajax loaded module will not “see” WP environment.

    Could this re-initialize global vars?

    Keeping testing.

    Even before the ‘require_once’ statement there’s a strange behavior:
    – declare a variable either in functions.php or in header.php OUTSIDE of a function (PHP expects this var to be global)
    – in header.php the variable is visible (has proper value)
    – in index.php the variable is destroyed
    – in a function (using the ‘global’ notation) the variable is destroyed

    Can someone help?

    WP shouldn’t destroy vars according to PHP manual:

    The scope of a variable is the context within which it is defined. For the most part all PHP variables only have a single scope. This single scope spans included and required files as well. For example:

    I have just read this…..

    ….
    WordPress doesn’t use standard PHP includes – so variables defined outside of a function, that is itself called within a template file, won’t work.
    ….

    What a shame!! It should be written with capital letters somewhere!

    Completely agree with you, Blutarsky. It doesn’t make sense that one cannot define variable in the header file for all subsequent template pages to use.

    I had to take time to figure out why it wouldn’t work. And then repeat each variable calculation in each template as a result.

    actually if you specifically declare them as global they work across other pages. just tested and it works. it’s weird i though that the global function was to let outside variable into a require or function, not the other way around.

Viewing 6 replies - 1 through 6 (of 6 total)
  • The topic ‘WP destroys header’s global vars?’ is closed to new replies.