Jump to content

ERROR Call to undefined function ..from an include file


Pixrael
 Share

Recommended Posts

Hi, I'm getting a Call to undefined function error when I try to call a function (eg. like the sample renderNavTree) that is in the _func.php file from a file (header.inc.php) included in _main.php. I already check the namespace, and that all the files are including correctly. All is OK If I make the call from _main.php, but it doesn't work if I do it from the file that is included. What foolish mistake am I do??

Link to comment
Share on other sites

Yes, if I call the function from _main.php ( <?php renderNavTree(); ?> or <?php echo renderNavTree(); ?> ) all work as expected, but when call the same function from an external file that is included in _main.php I get that error.. even TracyDebugger don't see this error... let me clarify the context:

_func.php <-- the function is declared here
_init.php <-- here load the _func.php
_main.php <-- call the function from here = ok ..here is include _header.inc.php
includes
   _header.inc.php <-- call the function = error

All the content from _header is include in main correctly when I don't call the function, so all seems to be fine until I use any function from _func.php file

I tried to include _func.php directly inside _header.php but don't work... but for me this no make sense because the functions was already loaded from _init.php in the PW workflow

Link to comment
Share on other sites

OK, that's all.. the famous namespace.. I try that before (because it's a common problem here in the forum) but I receive this error "Compile Error: Namespace declaration statement has to be the very first statement or after any declare call in the script" perhaps I let some whitespace before the <?php ... so for my record: the namespace statement should be declared in every every every php file that I use in my project? 

Thanks Zeka!!

Link to comment
Share on other sites

  • 3 months later...
On 21/04/2017 at 9:02 PM, Zeka said:

Are you sure about namespaces? Do you declare them in _header.inc.php?

Exact problem I just had with an undefined function, damn namespace! Keep forgetting it. Thanks @Zeka :)

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