leeming Posted August 26, 2006 Share Posted August 26, 2006 basicly i have my index page..[code]//call constrequire_once("wwc_const.php");//call functionsrequire_once("wwc_functions.php");[/code]which the const page, calls a function, which gets the id of the user from their login name...not sure if this is due to if the functions file is set as require_once (but i tried them both as include and same problem)...[quote]Fatal error: Call to undefined function: getidfromuser() in /home2/admin/public_html/wwc_const.php on line 8[/quote]wwc_const.php line #8[code] DEFINE("USERID", getIDFromUser($_SESSION[wwc_user]));[/code]wwc_functions.php function[code]function getIDFromUser($user){ $sql = "select Account_ID from Accounts WHERE Account_UName = '$user'"; $query = mysql_query($sql, cdb(0))or bavaderror($sql); $result = mysql_fetch_array($query); return $result[Account_ID];}[/code] Quote Link to comment https://forums.phpfreaks.com/topic/18683-function-defined-but-isnt-detected-inbedded-in-a-require/ Share on other sites More sharing options...
corbin Posted August 26, 2006 Share Posted August 26, 2006 Are you calling the function previous to the require_once statement? Quote Link to comment https://forums.phpfreaks.com/topic/18683-function-defined-but-isnt-detected-inbedded-in-a-require/#findComment-80541 Share on other sites More sharing options...
Ninjakreborn Posted August 26, 2006 Share Posted August 26, 2006 Try just an include, see if that works. Quote Link to comment https://forums.phpfreaks.com/topic/18683-function-defined-but-isnt-detected-inbedded-in-a-require/#findComment-80542 Share on other sites More sharing options...
leeming Posted August 26, 2006 Author Share Posted August 26, 2006 [quote author=businessman332211 link=topic=105663.msg422171#msg422171 date=1156556560]Try just an include, see if that works.[/quote]i did say i had tried that :S[quote author=leeming link=topic=105663.msg422166#msg422166 date=1156555783]not sure if this is due to if the functions file is set as require_once (but i tried them both as include and same problem)...[/quote]i am calling the function (in line order) before its defined, but functions can be declared at the bottom of the page arnt they... :S Quote Link to comment https://forums.phpfreaks.com/topic/18683-function-defined-but-isnt-detected-inbedded-in-a-require/#findComment-80544 Share on other sites More sharing options...
Ninjakreborn Posted August 26, 2006 Share Posted August 26, 2006 [quote] but functions can be declared at the bottom of the page arnt they... :S[/quote]functions HAVE to be declared before the function is called.As for your problem, just as a test try declaring the function on the same page, then see if it works, just try declaring it at the top of the page. See if you get the same error. If not then try the function_exists() function, see if it returns true.That will let you know if the function even exists, if it returns false when it's on the same page then something is wrong with your function itself. Quote Link to comment https://forums.phpfreaks.com/topic/18683-function-defined-but-isnt-detected-inbedded-in-a-require/#findComment-80545 Share on other sites More sharing options...
leeming Posted August 26, 2006 Author Share Posted August 26, 2006 [quote]functions HAVE to be declared before the function is called.[/quote]really? i was under the understanding that aslong as they are declared on the code, they can be called... (same understanding for other programming languages)i can put the functions on my main index page.. instead of in a functions page.. but i have never had this problem before.. (it also makes my index.php page more scruffy looking)if i declare the function above or below on the same page it still works.. (just since i have 3 custom functions called in the 'const' page.. which 2 of them (bavaderror() and cdb() are lengthy declarations), so if i put these on the main index page.. it defeats the purpose of having a functions.php page (???)...like i said.. i have never had this problem before.. if i cant fix it (without resorting to making my code look scruffy and disordered) i will have to be forced to rearange my code Quote Link to comment https://forums.phpfreaks.com/topic/18683-function-defined-but-isnt-detected-inbedded-in-a-require/#findComment-80547 Share on other sites More sharing options...
radar Posted August 26, 2006 Share Posted August 26, 2006 You can keep all your functions in a seperate file as is what I do.. Just put your require statement before you are going to call the function.. Thats all that needs to happen.. If its going to break your code -- you might re-think your coding style. Quote Link to comment https://forums.phpfreaks.com/topic/18683-function-defined-but-isnt-detected-inbedded-in-a-require/#findComment-80592 Share on other sites More sharing options...
trq Posted August 26, 2006 Share Posted August 26, 2006 [quote]functions HAVE to be declared before the function is called.[/quote]That is INCORRECT. You can use a function before it is declared in php. However... what you are trying to do is use a function before the file it is within is included. This will not work. Quote Link to comment https://forums.phpfreaks.com/topic/18683-function-defined-but-isnt-detected-inbedded-in-a-require/#findComment-80627 Share on other sites More sharing options...
Zane Posted August 26, 2006 Share Posted August 26, 2006 just switch the order of these two and it should workrequire_once("wwc_const.php");require_once("wwc_functions.php");just require the funcitons.php first and then const.php Quote Link to comment https://forums.phpfreaks.com/topic/18683-function-defined-but-isnt-detected-inbedded-in-a-require/#findComment-80632 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.