Not only case B has been reserved (since realpath returns false if the path cannot be resolved or the file does not exist according to docs ), if the file does not exist, this is a little silly.
Since this statement will return FALSE
:
realpath(__DIR__."/../file.php");
It:
file_exists(realpath(__DIR__."/../file.php"));
Is it really:
file_exists(FALSE);
As a side note:
realpath
will never return "FALSY". By this, I mean that it will never return what
== FALSE
, but not
=== FALSE
(e.g.
NULL
,
''
, 0, array ()). What for? Well, the real path will always include a link to root -
/
on * nix systems (Mac, Unix, Linux) and
C:\
on Windows, and these two lines will evaluate to true when used as a logical one (for example, in an if loop, while or for). This means that you can simply do:
if(!realpath(__DIR__."/../file.php"))
Or, if you need to have a real path, you can:
if(!($path = realpath(__DIR__."/../file.php")))
source share