Home PHP 'Call to undefined function' across two different includes?
Reply: 2

PHP 'Call to undefined function' across two different includes?

Cawley Published in 2017-09-14 10:03:34Z

I've got four PHP files that will form a simple template for my website:
- functions.php (with all of the main functions for the website - huge file)
- index.php (the main template file I'll be using, that will bring together the other three documents)
- header.php (header for the website)
- footer.php (footer for the website - this is where the problem occurs)

functions.php - a snippet. This function is simply on its own, not inside of a class or anything.

function LandingPageURL($Phrase, $LPID){
$LandingPageURL = "https://www.website.com/" . trim(strtolower(str_replace("d'","",str_replace(" ", "-", $Phrase)))) . "-" . trim($LPID) . "/";

header.php - no relevant parts. But, I am able to use functions from the functions.php file fine from here.

footer.php - relevant parts included. Error occurs here on line 27.

echo '<li><a href="' . LandingPageURL($ar_CHANNELS[$ar_CHANNELS_POS][$v_CH_PHRASE],$ar_CHANNELS[$ar_CHANNELS_POS][$v_CH_LPID])

The $ar_CHANNELS* variables are simply values from an array that I have.

index.php - relevant parts included.
This is included at the top of the file:

require ($_SERVER['DOCUMENT_ROOT'] . "/" . "resources/nw/lib/includes/functions.php");

This definitely works as I am calling other variables from functions.php, which are successful.
Further down the file, I include first the header.php file, then the footer.php file in identical ways:

require ($_SERVER['DOCUMENT_ROOT'] . "/" . "page/page-elements/header.php");
require ($_SERVER['DOCUMENT_ROOT'] . "/" . "page/page-elements/footer.php");

When the footer.php is included, and I load the webpage, I get the error message:

Fatal error: Call to undefined function LandingPageURL() in C:\Hosting\website\httpdocs\page\page-elements\footer.php on line 27

Is it something that I'm doing wrong, calling a function from another file that is included into my main index.php file? I made sure to use 'require', so that I knew that functions.php was being pulled into the index.php.

mracer164 Reply to 2017-09-14 10:08:45Z

The functipns.php file has to be included inside footer.php if you want to use its functions there.

Cawley Reply to 2017-09-14 13:57:05Z

Rather embarrassingly, the whole problem was caused by not properly closing a preceding function.

You need to login account before you can post.

About| Privacy statement| Terms of Service| Advertising| Contact us| Help| Sitemap|
Processed in 0.306134 second(s) , Gzip On .

© 2016 Powered by cudou.com design MATCHINFO