I have the following directories and files:
└── project
├── index.php
└── lib
├── file1.php
└── file2.php
<?php
//index.php
include 'lib/file1.php';
<?php
//file1.php
include 'lib/file2.php';
<?php
//file2.php
echo 'this is from an echo statement in file2.php';
This does work when I try it in the browser as I expected. In particular I think the include statement in file1.php makes sense because it uses a path to file2.php relative to the location of index.php which includes file1.php and so is the location that file1.php's code will be executed.
However, I was surprised that if I change the include statement in file1.php to:
include 'file2.php';
it still works.
I would like to understand why both include statements work and get an idea of which of the two is the more correct.