Page 1 of 2
getMenu() .... why is it an undefined function?
Posted: Mon Apr 08, 2013 3:46 am
by simonmlewis
Code: Select all
$menu = $_GET['menu'];
if ($menu != "")
{
function getMenu()
{
$thismenu="includes/menu/".$_GET['menu'].".inc";
if (file_exists($thismenu))
{
include $thismenu;
}
else
{
echo "<meta http-equiv='Refresh' content='0 ;URL=/error'>";
}
}}
..............
$menu = $_REQUEST['menu'];
if(isset($_REQUEST['menu']))
{ getMenu();}
I am getting the error in our logs:
[text][08-Apr-2013 05:49:47] PHP Fatal error: Call to undefined function getmenu() in /home/site/public_html/index.php on line 641[/text]
641 is the latter 'getmenu'.
Why am I getting this?
Re: getMenu() .... why is it an undefined function?
Posted: Mon Apr 08, 2013 12:28 pm
by requinix
Because the function isn't defined.
And before you say "yes it is, it's right there", notice that you define it inside an if block. If that condition isn't true then the function won't be defined.
Re: getMenu() .... why is it an undefined function?
Posted: Mon Apr 08, 2013 12:33 pm
by simonmlewis
But it's only calling the function if $menu is requested in the URL. If it is, it's also called in the functions.
Isn't it?
Re: getMenu() .... why is it an undefined function?
Posted: Mon Apr 08, 2013 2:11 pm
by requinix
Actually one uses the URL and the other uses whatever information is available, including POSTed data.
Is that actually your code? Did you paraphrase or simplify the code for your post?
Re: getMenu() .... why is it an undefined function?
Posted: Mon Apr 08, 2013 2:14 pm
by simonmlewis
That is it, apart from code not related to it. One is te bit to draw in the at, one is the function. He should it be then?
Re: getMenu() .... why is it an undefined function?
Posted: Mon Apr 08, 2013 2:42 pm
by requinix
What is the URL of this page?
Re: getMenu() .... why is it an undefined function?
Posted: Mon Apr 08, 2013 2:45 pm
by simonmlewis
I varies, but via the ht access, it would include ...&menu=categ...
Re: getMenu() .... why is it an undefined function?
Posted: Mon Apr 08, 2013 5:05 pm
by simonmlewis
Is this correct?
Code: Select all
$menu= isset($_GET['menu']) ? $_GET['menu'] : null;
$menu = $_REQUEST['menu'];
if ($menu != "")
{ getMenu();}
Re: getMenu() .... why is it an undefined function?
Posted: Wed Apr 10, 2013 5:26 am
by simonmlewis
Answer: No. I am still getting the errors.
What should it be??
Re: getMenu() .... why is it an undefined function?
Posted: Wed Apr 10, 2013 5:45 am
by simonmlewis
Code: Select all
function getMenu()
{
$thismenu="includes/menu/".$_GET['menu'].".inc";
if (file_exists($thismenu))
{
include $thismenu;
}
else
{
echo "<meta http-equiv='Refresh' content='0 ;URL=/error'>";
}
}
Should it be like this then - just a function there NOT inside an if statement??
Re: getMenu() .... why is it an undefined function?
Posted: Wed Apr 10, 2013 1:52 pm
by requinix
Yes actually, you should define functions and classes and such at the very top level - not inside anything conditional.
I still don't know why it thinks the function is undefined. Moving it to the top should definitely fix it.
Re: getMenu() .... why is it an undefined function?
Posted: Wed Apr 10, 2013 1:56 pm
by simonmlewis
It was always at the top. But I have tried it outside the if statement. Is this what it should be, outside the IF?
Re: getMenu() .... why is it an undefined function?
Posted: Wed Apr 10, 2013 3:29 pm
by requinix
If it's inside something then it's not at the top.
Yes, outside. Outside everything.
Re: getMenu() .... why is it an undefined function?
Posted: Thu Apr 11, 2013 5:12 am
by simonmlewis
Thanks. Now trying that. Will see in the morning if all those errors have gone.
Re: getMenu() .... why is it an undefined function?
Posted: Mon Apr 15, 2013 8:21 am
by simonmlewis
Errors gone!