php.net |  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
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: divinity76 at gmail dot com
New email:
PHP Version: OS:

 

 [2020-09-27 11:43 UTC] divinity76 at gmail dot com
Description:
------------
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:
---------------
<?php
var_dump(basename("/tmp","mp"));
var_dump(basename("/tmp","tmp"));


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


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


Patches

Pull Requests

History

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

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

$ basename /tmp mp
t
$ basename /tmp 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] sjon@php.net
-Status: Verified +Status: Not a bug
 [2020-09-27 12:44 UTC] sjon@php.net
.
 [2020-09-27 14:29 UTC] divinity76 at gmail dot com
@ sjon@php.net
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 https://www.gnu.org/software/coreutils/manual/html_node/basename-invocation.html#basename-invocation ) 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: Sun Dec 22 06:01:30 2024 UTC