Jump to content

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

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.