Forum Moderators: coopster
the way this was set up is very ugly. unfortunately, i have inherited it and don't have the time to go through and clean it up.
my problem is that i want to include another piece of code to all pages on the server, without having to go through the hassle of what i posted above. so i put a nice little include in one of these already included files to include my new piece of code.
if i execute the function in the new include page from the file it is included in, it works fine. problem lies when i call it from the actual page, it won't work, throwing up a php fatal error: call to undefined function.
i know the new file is being included as i put an echo statement in there to echo 'blah' and sure enough, blah appears on the screen.
is it because it is nested too deep? i'm going nuts trying to figure this out.
Your best bet may be to use auto_prepend_file [us2.php.net] as it will make everything much easier :)
Good luck!
As a side note, what I like to do is put all my include files in a /lib directory and include them all into a .h file first and then include that .h file in the host document. It makes it all a lot easier, maybe you might be able to do something like that.
eg:
/example/lib
example1.inc
functions...
example2.inc
classes..
/example
example.h
@include("lib/example1.inc");
@include("lib/example2.inc");
example.php
@include("example.h");
Works for me, does anyone else have a suggestion for a best practice method of handling include files? I would be very interested to hear how other people have solved the problems associated with them.
./includes
./includes/config.php
./includes/functionsorclass.php
./includes/functionsorclass2.php
config.php
--------------------
Variables that can be changed
-----------------------
Sql information
-------------------------
include files
------------------
include('functionsorclass.php');
include('functionsorclass2.php');
index.php
--------------------
include ('includes/config.php');
Firstly, included files are not parsed:
When a file is included, parsing drops out of PHP mode and into HTML mode at the beginning of the target file, and resumes again at the end. For this reason, any code inside the target file which should be executed as PHP code must be enclosed within valid PHP start and end tags.
Secondly, ending an included php file with just .inc is a very bad thing to do. If someone accesses this file directly they will be able to view the php code itself as regular text, unless the server is specifically set to parse this extension, but this is not default. You are, however, correct in saying that filename.php.inc will be parsed correctly. :)