|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
[2015-05-28 12:20 UTC] cmb@php.net
-Package: SPL_Types
+Package: SPL related
[2018-08-18 16:44 UTC] cmb@php.net
-Status: Open
+Status: Analyzed
-Assigned To:
+Assigned To: cmb
[2018-08-18 16:44 UTC] cmb@php.net
[2018-08-19 15:45 UTC] cmb@php.net
[2018-08-22 13:41 UTC] cmb@php.net
[2018-08-22 13:41 UTC] cmb@php.net
-Status: Analyzed
+Status: Closed
|
|||||||||||||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Tue Oct 28 14:00:01 2025 UTC |
Description: ------------ The test script provided below will fail with a RuntimeException: PHP Fatal error: Uncaught exception 'RuntimeException' with message 'SplFileInfo::getLinkTarget(): Empty filename' in test.php:10 What makes things really nasty: adding any of these statements before $entry->getLinkTarget() will make things work, there will be no exception being thrown: - readlink($entry->getPathName()) - $entry->isLink() Test script: --------------- <?php symlink('/no/such/directory', 'foo'); $file = new \SplFileInfo('foo'); var_dump($file->getLinkTarget()); $di = new \DirectoryIterator('.'); foreach($di as $entry) { if('foo' === $entry->getFilename()) { var_dump($entry->getLinkTarget()); } } Expected result: ---------------- I expect a consistent behavior. Either a call to getLinkTarget() on an invalid symlink shall always result in an exception or - what I would prefer - never. But the behavior should neither change depending on whether the DirectoryIterator is used or SplFileInfo directly; nor should it change depending on other methods/function calls. The documentation for SplFileInfo::getLinkTarget() is also not consistent with that behavior, it says: "The target may not be the real path on the filesystem. Use SplFileInfo::getRealPath() to determine the true path on the filesystem." But the described behavior looks like a call to realpath was already executed internally.