Variables scope
-
I am using one of the pages, to display a list. I have the following in the page:
<? php
include_once “myFunctions.php”;
include_once “myDeclarations.php”;
displayText();
?>Inside myFunctions.php, I have the following function:
function displayText() {
GLOBAL $textToDisplay;
echo “Testing WordPress”;
echo $textToDisplay;
}Inside myDeclarations.php, I have the following:
$textToDisplay = “This is a test”;
When I go to that page, it only displays: Testing WordPress. The variable $textToDisplay is not passed. It seems as if the include file that has the function in it, is recognized, but the variable in the other file, is not. How do I deal with this scope issue in WordPress?
-
Sorry, you are in the wrong forum and need to head over to http://wordpress.ORG/support/ as that is where self-hosted wordpress blogs using the software from wordpress.ORG are supported.
These forums are for those hosted here on the wordpress.COM free hosting service and things here work differently and our answers typically will not work for you.
If you do not know the difference, see this support document: http://en.support.wordpress.com/com-vs-org/ .
-
- The topic ‘Variables scope’ is closed to new replies.