- This topic is empty.
Viewing 2 posts - 1 through 2 (of 2 total)
Viewing 2 posts - 1 through 2 (of 2 total)
- The forum ‘Back End’ is closed to new topics and replies.
The forums ran from 2008-2020 and are now closed and viewable here as an archive.
Home › Forums › Back End › My dumb function is not working and there’s nothing wrong with it either, at least not obviously…
Hi guys,
I’m calling a functions.php at the top of my file and then calling some variables right after.
Then I use the functions, mainly of include and echo functions, in the page somewhere. The functions work based on the fact that the variable exists.
For example:
functions.php
function the_title()
{
$title = "Hello world";
$title .= $page_title; //$page_title is declared in the webpage
echo $title;
}
?>
index.php
$page_title="this is my index page.";
?>
bleh bleh all the head tags and stuff...
bleh bleh all the closing tags...
Now you get my situation.
The two functions that don’t work are:
function the_name()
{
echo $level_name;
}
function the_page()
{
echo $level_page;
}
Don’t they look perfectly legit?
The variables are declared in the same way–
$level_number = "";
$level_name = "Welcome!";
$level_page = "Home Page";
?>
that’s everything before my .
Now when I call the function:
It doesn’t work. The page still loads–means there’s no syntax problem. The function just doesn’t echo anything. So what’s wrong? All looks legit…
Additional info: If I abort the function and just call “echo $level_name;”, it works. So it’s something with my function…
Red
Your issue is one of scope. Inside your functions, any variables declared externally are not known unless their value is passed as a parameter of the function or accessed using GLOBAL within the function.
Regards,
Michael