Oihana PHP

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 :

  1. Unix / macOS / Linux Uses the HOME environment variable if it is set and non‑empty.
  2. Windows (≥ XP) Combines HOMEDRIVE + HOMEPATH (e.g. C: + \Users\John) if both are available.
  3. 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
throws
RuntimeException

When the home directory cannot be determined.

example
$home = getHomeDirectory(); // "/home/alice" or "C:/Users/Alice"
author

Marc Alcaraz (ekameleon)

since
1.0.0
Return values
string

Canonical absolute path to the user’s home directory.


        
On this page

Search results