When calling with an absolute path, such as '/Users/joachim/bin/drupal_hooks/8', this function returns FALSE.
This is because the call to explode produces an array like this:
Array
(
[0] =>
[1] => Users
[2] => joachim
[3] => bin
[4] => drupal_hooks
)
When the directory path is then built up from the pieces, the first one will be an empty string.
For that matter, this looks wrong:
foreach ($components as $component) {
$recursive_path .= $component;
because the exploding on DIRECTORY_SEPARATOR means that none of the pieces contain DIRECTORY_SEPARATOR. Therefore, the joining will just smush the pieces together without slashes.