Variables vs Functions in template files
-
Can someone explain what is the difference in scope here
If in my functions.php I had this
$blue = 'blue'; function red() { echo 'red'; }
then in sidebar.php
<?php echo $blue; ?> <?php red(); ?>
If I included the sidebar with get_sidebar(), which involves a “require”, the function red() is available and works, but the variable blue does not exist.
My question is, why is the function red() available, but the variable $blue, not available? (unless I make $blue a global).
Thanks in advance!
Viewing 1 replies (of 1 total)
Viewing 1 replies (of 1 total)
- The topic ‘Variables vs Functions in template files’ is closed to new replies.