eternallygeek Posted July 4, 2009 Share Posted July 4, 2009 I am having problems with some PHP code that I am writing. I have a function in a separate php that is included in another php file with html (both shown below). I obviously see the "test() returns...." text but not the return value of 5 from the function. Any thoughts or nudges in the right direction? Here is the html 'calling code'.... (test.php) <html> <?php include '/scripts/testing.php' ?> <head> <title>stuff</title> </head> <body> <p>test() returns....</p> <?php echo test(); ?> </body> </html> Here is the php function library.... (testing.php) <?php function test() { return "5"; } ?> Thanks! Link to comment https://forums.phpfreaks.com/topic/164785-solved-problems-with-return-value-from-function-in-included-php-file/ Share on other sites More sharing options...
Alex Posted July 4, 2009 Share Posted July 4, 2009 Are you sure the file is being included correctly? Make sure the path is right, you're also missing a ; try: include 'scripts/testing.php'; Link to comment https://forums.phpfreaks.com/topic/164785-solved-problems-with-return-value-from-function-in-included-php-file/#findComment-868960 Share on other sites More sharing options...
eternallygeek Posted July 5, 2009 Author Share Posted July 5, 2009 Thanks for the reply AlexWD! The semi missing was a typo, I reduced the code down for ease of debugging and placing on the forums here. You were right in pointing me to the included file. I moved the include file into the same directory and included just the filename in quotes. That worked just fine, so there was something wrong with the path. Now I just need to go off and figure out the right path on my webserver so that I can put that file back where I intended it. Link to comment https://forums.phpfreaks.com/topic/164785-solved-problems-with-return-value-from-function-in-included-php-file/#findComment-869439 Share on other sites More sharing options...
PFMaBiSmAd Posted July 5, 2009 Share Posted July 5, 2009 It's usually a good idea to form an absolute file system path starting with the document_root folder - include $_SERVER['DOCUMENT_ROOT'] . '/path_to_file/file.php'; Link to comment https://forums.phpfreaks.com/topic/164785-solved-problems-with-return-value-from-function-in-included-php-file/#findComment-869440 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.