Beware of relative symbolic links like this one (ext4 file system on Ubuntu) :
vincent@vincent:~/Bureau/dirscan$ readlink sandbox/roulant/voiture/cabriolet/ln-loop-relative
../..
In this case, realpath may return false :
<?php
var_dump(realpath('sandbox/roulant/voiture/cabriolet/ln-loop-relative'));
var_dump(realpath('sandbox/roulant/voiture/cabriolet/ln-loop-relative/moto'));
?>
But you can fix it by clearing the realpath cache, this way :
<?php
var_dump(realpath('sandbox/roulant/voiture/cabriolet/ln-loop-relative'));
clearstatcache(true);
var_dump(realpath('sandbox/roulant/voiture/cabriolet/ln-loop-relative/moto'));
?>