ktalebian Posted May 1, 2008 Share Posted May 1, 2008 Hi there, for some reason, I am having problem accessing variables and functions that are in a file that is included in another: fun.php <?php function Name() { // doing stuff return $someVariable; } $string = 'something'; echo "This string says $string"; ?> page.php <?php include 'fun.php'; echo $string; $test = Name(); ?> Now, when I run the code above, i don't get anything from echo $string. But, the echo "This string says $string" is displayed. I also get an Fatal error saying that the function I am referring to is not defined. Why?? Thanks! Link to comment https://forums.phpfreaks.com/topic/103685-include-problem/ Share on other sites More sharing options...
mescal Posted May 1, 2008 Share Posted May 1, 2008 Hi I tried it on my server and the code is working fine. But actually your function is doing nothing, the output is outside the function grtZ mescal Link to comment https://forums.phpfreaks.com/topic/103685-include-problem/#findComment-530884 Share on other sites More sharing options...
ktalebian Posted May 1, 2008 Author Share Posted May 1, 2008 Hi there, I know the function is not doing anything, i just wrote it as an example. I have WAMP installed on my PC (i want to finish the website before I upload it to the server). Could it be that some sort of a configuration is not setup correctly? Cause I am also getting problems with using SESSIONS! Thanks! Link to comment https://forums.phpfreaks.com/topic/103685-include-problem/#findComment-531070 Share on other sites More sharing options...
gammaman Posted May 1, 2008 Share Posted May 1, 2008 On the page with the error modify your code to just this. <?php include ('fun.php'); ?> Do not echo or assign variables. Link to comment https://forums.phpfreaks.com/topic/103685-include-problem/#findComment-531089 Share on other sites More sharing options...
ktalebian Posted May 1, 2008 Author Share Posted May 1, 2008 But I need to use the variables! THere is no point of just including it if I cannot use it! Link to comment https://forums.phpfreaks.com/topic/103685-include-problem/#findComment-531135 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.