user9059272
user9059272

Reputation:

What does mean by "symlinks resolved" in the description of magic constant __FILE__?

I'm using PHP 7.2.0

Below is a description of magic constant __FILE__ :

The full path and filename of the file with symlinks resolved. If used inside an include, the name of the included file is returned.

I didn't understand meaning of the clause "filename of the file with symlinks resolved"

Someone please make me understand the meaning of this clause with demonstrative suitable example of usage of magic constant __FILE__ accompanied by appropriate explanation.

Upvotes: 0

Views: 422

Answers (1)

deceze
deceze

Reputation: 522499

Symlinks (symbolic links) are "shortcuts" you can create in the filesystem to point one directory entry at any arbitrary other directory entry. On a *NIX shell, something like:

$ ln -s /foo/bar.php /baz

This establishes /baz as a symlink to /foo/bar.php. Whichever file you use now, they're effectively both the same.

Resolving symlinks means to look at a given path, recognise symlinks within it and replace them by the actual file path they point to. So, regardless of whether you do

$ php /baz

or

$ php /foo/bar.php

the __FILE__ constant will be resolved to the actual file path /foo/bar.php.

Upvotes: 4

Related Questions