Code to join filesystem path strings in PHP
Seems like the problem has been over thought.  This would be how I would write it.

&lt;?php

//$args = func_get_args();
$args = array('foo/', '/bar', 'fiz');

$paths = [];

foreach ($args as $arg) {
    $paths[] = trim($arg, DIRECTORY_SEPARATOR);
}

$paths = array_filter($paths);

echo DIRECTORY_SEPARATOR . join(DIRECTORY_SEPARATOR, $paths);


I don't see any need to leverage any exclusive PHP 5.6+ features to solve this.