php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Doc Bug #55308 pathinfo() options parameter not as expected
Submitted: 2011-07-28 10:33 UTC Modified: 2011-07-28 15:14 UTC
From: m dot ford at leedsmet dot ac dot uk Assigned: mgf (profile)
Status: Closed Package: *Directory/Filesystem functions
PHP Version: 5.3.6 OS:
Private report: No CVE-ID: None
 [2011-07-28 10:33 UTC] m dot ford at leedsmet dot ac dot uk
Description:
------------
The options parameter of pathinfo() does not seem to operate according to the description in the manual, nor as might be expected. The manual description implies that if an options value consisting of more than one of the bitwise PATHINFO_* constants is supplied, the return value will be a string consisting of all the parts requested; however, this is not the case -- only the part corresponding to the lowest bit is returned.

This seems both contrary to the documentation and completely illogical.

It would be much better if pathinfo returned an array of the requested elements, *except* when a single element is requested. If this is deemed not possible due to BC, either the behaviour or the documentation should be fixed so that they match!

Test script:
---------------
<?php
$info = pathinfo('/path/name/file.ext', PATHINFO_FILENAME+PATHINFO_EXTENSION);
var_dump($info);
?>


Expected result:
----------------
EITHER:
   array(2) {
     ["extension"]=>
     string(3) "ext"
     ["filename"]=>
     string(4) "file"
   }

OR:

   string(8) "file.ext"



Actual result:
--------------
string(3) "ext"


Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2011-07-28 11:20 UTC] laruence@php.net
-Type: Bug +Type: Documentation Problem
 [2011-07-28 11:20 UTC] laruence@php.net
generally speaking we mean add by "|", which is PATHINFO_FILENAME|PATHINFO_EXTENSION, 

but nerver mind, it's not the problem's reason.

and I think the doc should correct the description about the second paramter: "You can specify which elements are returned with optional parameter options. It composes from PATHINFO_DIRNAME, PATHINFO_BASENAME, PATHINFO_EXTENSION and PATHINFO_FILENAME. It defaults to return all elements."

obviously "which elements" should be "which element".
 [2011-07-28 11:25 UTC] mgf@php.net
-Status: Open +Status: Assigned -Assigned To: +Assigned To: mgf
 [2011-07-28 11:25 UTC] mgf@php.net
OK, I've already got a doc patch on the go for this - will finish and commit soon.
 [2011-07-28 15:14 UTC] mgf@php.net
-Status: Assigned +Status: Closed
 [2011-07-28 15:14 UTC] mgf@php.net
This bug has been fixed in SVN.

Snapshots of the sources are packaged every three hours; this change
will be in the next snapshot. You can grab the snapshot at
http://snaps.php.net/.

 For Windows:

http://windows.php.net/snapshots/
 
Thank you for the report, and for helping us make PHP better.


 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Tue Apr 30 17:01:30 2024 UTC