Jump to content

calling functions


jeff5656

Recommended Posts

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!

Link to comment
https://forums.phpfreaks.com/topic/204188-calling-functions/
Share on other sites

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.

Link to comment
https://forums.phpfreaks.com/topic/204188-calling-functions/#findComment-1069452
Share on other sites

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.

Link to comment
https://forums.phpfreaks.com/topic/204188-calling-functions/#findComment-1069454
Share on other sites

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

Link to comment
https://forums.phpfreaks.com/topic/204188-calling-functions/#findComment-1069534
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.