I’m setting an instance of an object in functions.php, like this:
$foo = new Foo;
When I dump it out in index.php, it returns the instance. However, in footer.php this:
var_dump($foo)
returns NULL.
This all inside a WordPress-theme. Any ideas?
The code in footer.php is in a different scope. You can try making it a global with:
in your functions.php file and then at the top of your footer.php file add:
Your var_dump should then return the object.
http://php.net/manual/en/language.variables.scope.php