Ok, I know I'm overlooking something REALLY easy here, but I'm stumped as to what.

I have a file called makemenu.php which I must call repeatedly from another file. I do so as follows:

      include "makemenu.php";

The problem is that a function called WriteMenu within makemenu.php gets redeclared and comes up with the error: Cannot redeclare writemenu() (previously declared in...

When I add the code:

if (!function_exists('WriteMenu'))
  {
  }

to my code, instead of processing it the first time & ignoring it the second, I get this error: Call to undefined function WriteMenu() ...

Help! I really MUST be able to call this file over & over again in a loop. I'd prefer to have it in a separate file rather than having it hard-coded into the calling file, as I call it from other files as well. Any ideas?

    you shouldn't need to include a file more than once, what ever you need in it that needs to be repeated should be a function, then you can just include the file once, and call the function as many times a needed.

      Ok... Let's see. The first part of the file I'm calling calls a function at the bottom of the file. What you're saying is that the entire piece of code can be a function; then, whatever file needs this function includes the file (once) and then calls the function as many times as needed. Is that right? Sounds easy!

        daltman1967;10961694 wrote:

        Is that right?

        yes.

        basicly, any piece of code called more than once should be a function.

          dagon;10961695 wrote:

          yes.

          basicly, any piece of code called more than once should be a function.

          Or a class method. 😉 (Which I suppose is, technically, still a function in PHP.)

            it its just a string, then a variable would also do.

              As per my opinion don't include a file twice but whatever you require put it in function so just include the file only one time.

                Write a Reply...