0

Recently I found that many people write code like: ROOT_FOLDER."./".$file when they're concatenating paths.
Isn't it the same with ROOT_FOLDER.$file? Does the dot slash make sense in the middle of two paths?

ChandlerQ
  • 1,428
  • 2
  • 21
  • 29
  • `.` means current folder. `www.abc.com/././home.php` will be the same as `www.abc.com/home.php` – Tun Zarni Kyaw Jan 03 '14 at 03:37
  • This is standard when you want to include your home directory in the file path where `ROOT_FOLDER = /home/amareknight` and if exected from `public_html` it will equate to, `/home/amareknight/public_html/file.ext` – Ohgodwhy Jan 03 '14 at 03:40
  • People do many strange things ;) This "./" in particular is completely unnecessary. It is a different thing if you have seen ROOT_FOLDER . "/" . $file, though. Can you double check it? – Grzegorz Jan 03 '14 at 03:54
  • @Grzegorz I'm sure it's dot slash... Everywhere the project wants to concatenate paths, it will use this format, it seems like they're following some rules... – ChandlerQ Jan 03 '14 at 03:57
  • @AmareKnight: The only reason I can come up to is protection against an empty ROOT_FOLDER (""). If ROOT_FOLDER is "" then `ROOT_FOLDER . "/" . $file` would point to a file in the root of the file system (not good.) If developer assumes that ROOT_FOLDER can be "" or anything that *has to* end with "/" then using "./" will always work with creating a file either in ROOT_FOLDER or current directory. I see no other reason. – Grzegorz Jan 03 '14 at 04:04
  • @Grzegorz Agree with you. Thanks – ChandlerQ Jan 03 '14 at 04:10
  • @Ohgodwhy What do you mean by standard? It makes no difference having "./" or not in your case. I agree with Grzegorz's idea. – ChandlerQ Jan 03 '14 at 04:12

1 Answers1

-2

The dot slash is required if ROOT_FOLDER does NOT include a trailing slash.And in the case of many file systems: a slash at the beginning of a string usually denotes the root.

Assumptions:

 $ROOT_FOLDER_A = www/yoursite
 $ROOT_FOLDER_B = www/yoursite/
 $file = something.html

If you wanted to access $file you would need:

 ROOT_FOLDER_A."/".$file

OR ROOT_FOLDER_B.$file

JBC
  • 112
  • 5
  • 1
    Sorry but my question is about "./" not "/", if ROOT_FOLDER doesn't include trailing slash, people should concatenate with "/" not "./" – ChandlerQ Jan 03 '14 at 04:09
  • Sorry, I presumed it was a typo and/or misread. If you've seen it as ROOT_FOLDER "dot slash", could you have your slash and/or variable one off? I've only ever seen dots in that sequence when concatenating a string, otherwise the variable is ROOT_FOLDER. – JBC Jan 03 '14 at 06:14
  • Could it be a Designated Initializer http://stackoverflow.com/questions/7487918/what-means-the-dot-before-variable-name-in-struct Another thought comes to mind to specify current directory. Where a preceding slash indicates root, dot dot slash indicates up one level and dot slash may mean current directory, not the root directory (for example: www/yoursite/dir/path/file could be displayed as yoursite.com/./file and indicate dir/path/file; though I'm not familiar with using it in this fashion. – JBC Jan 03 '14 at 06:19