php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Doc Bug #81079 pathinfo() unexpected path/filename separation with trailing slash
Submitted: 2021-05-24 14:57 UTC Modified: 2021-05-25 12:13 UTC
Votes:1
Avg. Score:4.0 ± 0.0
Reproduced:0 of 0 (0.0%)
From: info at kgsw dot de Assigned:
Status: Verified Package: *Directory/Filesystem functions
PHP Version: 7.3.28 OS: Linux Mint 20.1
Private report: No CVE-ID: None
Have you experienced this issue?
Rate the importance of this bug to you:

 [2021-05-24 14:57 UTC] info at kgsw dot de
Description:
------------
using linux command line, sometimes trailing slash will make sure to identify a directory; 

my own, manual functions would first split path from filename at the _last_ slash;
 which would find NO filename, only path, in that example;

for me unexpected - so need documentation or is a bug? 

I could not find PHP 7.4.3 in the options dropbox to select using:
PHP 7.4.3 (cli) (built: Oct  6 2020 15:47:56) ( NTS )

once reported on Win2k - but discarded as "no URL function" - but I think, this is not the point - it is just unexpected
https://bugs.php.net/bug.php?id=41834

If you still insist on that IMHO strange behaviour, I would like to add a note to the manual

Test script:
---------------
php > var_dump( pathinfo('/home/user/backup.2021-05-24/'));
array(4) {
  ["dirname"]=>
  string(10) "/home/user"
  ["basename"]=>
  string(17) "backup.2021-05-24"
  ["extension"]=>
  string(10) "2021-05-24"
  ["filename"]=>
  string(6) "backup"
}

Expected result:
----------------
array(4) {
  ["dirname"]=>
  string(10) "/home/user/backup.2021-05-24"
  // no more set - cause no filename given
}


Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2021-05-25 12:13 UTC] cmb@php.net
-Status: Open +Status: Verified
 [2021-05-25 12:13 UTC] cmb@php.net
Well, that behavior might be confusing, but it is long
standing[1], and consistent with basedir() and dirname(), so it
can't be changed. A note in the docs won't hurt.

[1] <https://3v4l.org/aXYbl>
[2] <https://3v4l.org/mlkXI>
 
PHP Copyright © 2001-2021 The PHP Group
All rights reserved.
Last updated: Fri Jul 30 09:01:24 2021 UTC