Jump to content

[solved] Init functions not available in includes?


Robin S
 Share

Recommended Posts

There is probably an obvious answer to this but I am suffering a brain-fade:

In my auto-prepended "_init.php" I have a function defined...

function myFunction() {
    echo "hello!";
}

I can use that function in my auto-appended "_main.php" or in a template file (e.g. "home.php") no problem.

But why is it undefined if I call it in a file that is included in _main.php or home.php?

include "./my_include.php";

my_include.php

// results in "Call to undefined function myFunction()"
myFunction();

I was expecting _init.php to have been prepended by the time myFunction() is called inside my_include.php - or does my_include.php get included before _init.php? I guess I'm not clear on the order of operations here. Do I have to include _init.php inside my_include.php, or is there some other simple way to make myFunction() available globally?

Link to comment
Share on other sites

this may be a namespace snafu - have you tried putting the namespace in front of the call inside the include, e.g. \ProcessWire\myFunction(); ?

to be clear, i include tons of functions from the init, in fact my _init includes a _func.php which the includes around 10 separate files all with functions and those all load and are usable everywhere; however i have run into the snafu of having to prepend the namespace for some reason within certain included files down the line

  • Like 5
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...