I’ve got the following file structure:
/
+--- inc/
| +--- lib1.php
+--- inc2/
| +--- lib2.php
| +--- view2.php
+--- view1.php
Both view1.php and view2.php include lib2.php. Lib2.php includes lib1.php. Graphically:
View1.php ---\
+---> Lib2.php ---> Lib1.php
View2.php ---/
However I cannot get this working, because the search paths are wonky. If I try to include “../lib1.php” then only view2.php works. If I try to include “inc/lib1.php”, then only view1.php works. The other view always complains about file not found.
What should be the correct way of handling this?
If you use php >= 5.3 you can use
__DIR__to build the path. If not, usedirname(__FILE__)So in lib2.php, just put this: