|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #80155 basename("/tmp","tmp") fails
Submitted: 2020-09-27 11:43 UTC Modified: 2020-09-27 12:44 UTC
From: divinity76 at gmail dot com Assigned:
Status: Not a bug Package: *Directory/Filesystem functions
PHP Version: 7.4.10 OS: both Windows and Linux
Private report: No CVE-ID: None
 [2020-09-27 11:43 UTC] divinity76 at gmail dot com
running basename("/tmp","tmp") fails to remove the "tmp" suffix from the end of the name. 

tested on PHP 8.0.0 beta3 running on Linux, and PHP 7.3.7 running on Windows 10.

Test script:

Expected result:
string(1) "t"
string(0) ""

Actual result:
string(1) "t"
string(3) "tmp"


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2020-09-27 12:43 UTC]
-Status: Open +Status: Verified
 [2020-09-27 12:43 UTC]
Thank you for taking the time to write to us, but this is not
a bug. Please double-check the documentation available at and the instructions on how to report
a bug at

while unexpected - this behavior matches what GNU's basename returns, see:

$ basename /tmp mp
$ basename /tmp tmp

I assume this is because once the entire pathname is removed, it would no longer be a suffix
 [2020-09-27 12:44 UTC]
-Status: Verified +Status: Not a bug
 [2020-09-27 12:44 UTC]
 [2020-09-27 14:29 UTC] divinity76 at gmail dot com
nowhere in the documentation do i see anything like "if the suffix is the whole name, it will not be cut off", perhaps it is a documentation issue then? 

wonder what the GNU basename documentation says about it, I'll take a look at that
 [2020-09-27 14:35 UTC] divinity76 at gmail dot com
it seems the GNU basename documentation (at ) doesn't say anything about what happens when the suffix matches the whole name, much like the PHP documentation
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Mon Apr 22 20:01:29 2024 UTC