Robin S Posted February 27, 2017 Share Posted February 27, 2017 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 More sharing options...
Macrura Posted February 28, 2017 Share Posted February 28, 2017 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 5 Link to comment Share on other sites More sharing options...
Robin S Posted February 28, 2017 Author Share Posted February 28, 2017 29 minutes ago, Macrura said: this may be a namespace snafu You are spot on - I have the ProcessWire namespace declared everywhere except in my included file. Thanks! Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now