hello forums !!
i would like to know if its possible to include file in a function..ie when a filename is given as an argument then it should be able to include that..
index.php

doInclude("page1");

functions.php

doInclude($file){
 return include($file.".php");
}

Will this function work ? else what s the effective function then, I would also like to make one for class files(to include it and create objects).
please Help.

    Weedpacket wrote:

    Have you tried it?

    Obviously not.

    Please try your code and do some testing before asking for help.

    If something is broken or you just don't have a clue on how to do something, then make a post.

      It wont, but this will:

      doInclude($file)
      {
              require_once($file . '.php');
      } 
      

        It wont, but this will:

        That will not work either. The same fix to make it work would also fix the OP's code snippet.

          I assure you, it will, have you tried it? I am doing it right now 🙂 !

          Obviously you need to call the function if this is what you misunderstood.

            I think what laserlight meant is that you need

            function doInclude( $file ) {
            ...
            }

            as opposed to just

            doInclude( $file ) {
            ...
            }

            The reason why the poster's initial code isn't working.

              So... did that resolve your issue? If so, don't forget to mark this thread resolved.

                Brad, do you have a macro for that post? 😉

                  Write a Reply...