0

I've got a file structure at work that looks like this:

root/
├─ directory/
│  ├─ main.php
│  ├─ code1.php
│  ├─ code2.php
│  ├─ script.php
script.php

The main.php script has several include() statements, and a couple of them look like this: include(code1.php), include(code2.php). This makes perfect sense to me, as it's just looking the code script within directory, since directory is the cwd.

But then there's a line include(.\script.php). I was cleaning up the codebase a bit (git was recently set up) and was looking to remove one of the duplicae script.php files, and based on the include statement, I removed the one inside of directory and left the one in root, because I thought the .\ syntax meant to jump up one level and search there instead.

Well, that broke everything, and reverting the commit and putting script.php back into directory fixed it. I've done some searching and there's a very similar question here asking about the difference between just using a ..\ and using \..\, which I understand, but my question is what is the purpose of using just one period, like .\? Clearly it's not to jump up one level like I thought, but it also seems to be unnecessary when looking for a file that exists at the same level as the original script that was called?

Thanks in advance!

  • Please write the correct path direction. `./` or `../`. One dot means current directory, two dots one directory up. – Markus Zeller Sep 07 '22 at 15:36
  • @MarkusZeller Ok gotcha. – confused_nomad Sep 07 '22 at 16:54
  • @Cid Yes that is actually exactly what I was looking for, not sure how I didn't manage to come across it. That answer you linked to is maybe the most direct answer to one of my questions I've ever encountered haha. Thank you! – confused_nomad Sep 07 '22 at 16:56
  • Relative paths often cause more problems than they solve. I suggest you compose absolute paths with `__DIR__` and `basename()` unless you have a strong reason to use relative paths. – Álvaro González Sep 08 '22 at 10:32

0 Answers0