Oihana PHP

realpathParent.php

Table of Contents

Functions

realpathParent()  : string
Resolves a path's parent and leaves its last segment as it stands.

Functions

realpathParent()

Resolves a path's parent and leaves its last segment as it stands.

realpathParent(string $path) : string

realpath() answers for the whole path, which is too much when the last segment is the thing being judged: a symbolic link would be replaced by what it points at, and a path that does not exist would answer false. This resolves everything above the last segment — so a linked ancestor cannot hide where a path really leads — and keeps the last segment verbatim.

When the parent cannot be resolved, because it does not exist, the path is canonicalized lexically instead: there is nothing on disk to ask.

Parameters
$path : string

The path to resolve.

Tags
example
use function oihana\files\path\realpathParent;

// On macOS, where /var is a link to /private/var:
realpathParent( '/var/folders/x/T' ) ; // '/private/var/folders/x/T'

// The parent is the filesystem root, and the result carries one separator, not two:
realpathParent( '/tmp' ) ;             // '/tmp'

// A link is kept as itself, never followed:
symlink( '/elsewhere' , '/tmp/pointer' ) ;
realpathParent( '/tmp/pointer' ) ;     // '/tmp/pointer'
author

Marc Alcaraz (ekameleon)

since
1.6.0
Return values
string —

The path with its parent resolved and its last segment untouched.

On this page

Search results