Req #76702 [Com]: pathinfo's $options should have a value for DIRNAME + FILENAME
| From: | jerry at jmweb dot net | Date: | Sat, 04 Aug 2018 20:42:31 +0000 |
| Subject: | Req #76702 [Com]: pathinfo's $options should have a value for DIRNAME + FILENAME | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-216583@lists.php.net to get a copy of this message | ||
Edit report at https://bugs.php.net/bug.php?id=76702&edit=1
ID: 76702
Comment by: jerry at jmweb dot net
Reported by: jerry at jmweb dot net
Summary: pathinfo's $options should have a value for DIRNAME
+ FILENAME
Status: Open
Type: Feature/Change Request
Package: Filesystem function related
PHP Version: Irrelevant
Block user comment: N
Private report: N
New Comment:
I vote for PATHINFO_DIRFILENAME. I see it more consistent to the existing PATHINFO_ family of
constants.
What is the next step? Unfortunately, I can't submit a patch since I do not know C. Also, what
release would this feature target if approved?
Previous Comments:
------------------------------------------------------------------------
[2018-08-04 20:38:17] requinix@php.net
Personally I would go for DIRFILE or DIRFILENAME - a combination of the DIRNAME and FILENAME
constants (and one that fits the current naming style) which should help users remember it.
------------------------------------------------------------------------
[2018-08-04 19:21:57] jerry at jmweb dot net
The output should follow the natural order of the file's path regardless of the order the
bitmask was created. So (PATHINFO_DIRNAME | PATHINFO_EXTENSION) would be identical to the
concatenation of pathinfo()'s matching indexes (['dirname'] . '/.' .
['extension']). The bitmask (PATHINFO_BASENAME | PATHINFO_FILENAME) would be normalized to
just (PATHINFO_BASENAME) and return only the equivalent of pathinfo()'s
(['basename']).
I now see that accepting a bitmask value will make things convoluted since:
PATHINFO_FILENAME | PATHINFO_EXTENSION -> same output as PATHINFO_BASENAME
PATHINFO_FILENAME | PATHINFO_BASENAME -> normalized to PATHINFO_BASENAME
PATHINFO_DIRNAME | PATHINFO_EXTENSION -> not useful
Introducing a new constant for the DIRNAME + FILENAME combination sounds like a better solution.
However, coming up an appropriate name escapes me at the moment. To kick-start the options, consider
these:
PATHINFO_FILEPATH
PATHINFO_FILENAMEPATH
PATHINFO_NO_EXTENSION
PATHINFO_EXTENSIONLESS
PATHINFO_DIRFILENAME
------------------------------------------------------------------------
[2018-08-04 13:47:32] a at b dot c dot de
The same way BASENAME is FILENAME+EXTENSION? It would fill a hole in the matrix:
dirname/filename.extension
------- -------- ********* EXTENSION
------- ******** --------- FILENAME
------- ******** ********* BASENAME
******* -------- --------- DIRNAME
******* ******** --------- ?[ROOTNAME? STEMNAME?]
(the remaining three dirname/filename/extension combinations aren't useful).
------------------------------------------------------------------------
[2018-08-04 07:08:40] requinix@php.net
So instead, how about a constant for the combined DIRNAME+FILENAME?
------------------------------------------------------------------------
[2018-08-04 06:45:37] a at b dot c dot de
How, for example, would (PATHINFO_DIRNAME | PATHINFO_EXTENSION) or (PATHINFO_BASENAME |
PATHINFO_FILENAME) be handled?
I'd be more inclined to write the test script as:
$path = '/dir/file.ext';
$newExt = '.ext2';
['dirname' => $dir, 'basename' => $file] = pathinfo($path);
$newPath = "$dir/$file$newExt";
But that may just be me.
------------------------------------------------------------------------
The remainder of the comments for this report are too long. To view
the rest of the comments, please view the bug report online at
https://bugs.php.net/bug.php?id=76702
--
Edit this bug report at https://bugs.php.net/bug.php?id=76702&edit=1