getHomeDirectory.php
Table of Contents
Functions
- getHomeDirectory() : string
- Returns the current user’s home directory as a **canonical** path.
Functions
getHomeDirectory()
Returns the current user’s home directory as a **canonical** path.
getHomeDirectory() : string
Resolution strategy – in order :
- Unix / macOS / Linux
Uses the
HOME
environment variable if it is set and non‑empty. - Windows (≥ XP)
Combines
HOMEDRIVE
+HOMEPATH
(e.g.C:
+\Users\John
) if both are available. - Failure
Throws a
RuntimeException
when no recognised combination is found.
The resulting string is passed through canonicalizePath() so that path separators are normalized (backslashes → slashes) and redundant slashes are removed.
Tags
Return values
string —Canonical absolute path to the user’s home directory.