jeff5656 Posted June 8, 2010 Share Posted June 8, 2010 Trying to learn about functions. Before I call a user-created function, I have to read that function correct? So if I have a file called "functions.php" that lists a bunch of functions, do I have to put include ../functions.php at the beginning of *every* page that I will be calling a function? Or can I include the functions.php in just the index.php page? That seems a little tedious I guess, but I want to do what the standard is for reading-in the user-created functions. Because php's built in functions are somehow read without having an include file, so is there a way to treat my created functions the same way? Thanks! Quote Link to comment https://forums.phpfreaks.com/topic/204188-calling-functions/ Share on other sites More sharing options...
KevinM1 Posted June 8, 2010 Share Posted June 8, 2010 There's no way around it - you need to have your function definitions in the same file as the code that's trying to invoke your user-defined functions. This can be done by include and/or require, or by explicitly writing the definitions in the file that will be invoking the functions itself. Most languages require one to manually import namespaces, or header files, or other similar library code. Quote Link to comment https://forums.phpfreaks.com/topic/204188-calling-functions/#findComment-1069452 Share on other sites More sharing options...
cyberRobot Posted June 8, 2010 Share Posted June 8, 2010 You'll need to place the include statement on every page that needs to use those functions. Do you have any other file that's already being included on every page? For example, do you have a header or footer file being included? If so, you should be able to add the include statement for functions.php in one of those files. Quote Link to comment https://forums.phpfreaks.com/topic/204188-calling-functions/#findComment-1069454 Share on other sites More sharing options...
ignace Posted June 8, 2010 Share Posted June 8, 2010 You'll need to place the include statement on every page that needs to use those functions. Unless you use the directives auto_prepend_file or auto_append_file php_value auto_prepend_file "includes/functions.php" http://php.net/manual/en/ini.core.php -- scroll down to data handling Quote Link to comment https://forums.phpfreaks.com/topic/204188-calling-functions/#findComment-1069534 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.