php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #48361 SplFileInfo::getPathinfo no returning info of path
Submitted: 2009-05-22 10:30 UTC Modified: 2010-04-27 10:56 UTC
Votes:4
Avg. Score:5.0 ± 0.0
Reproduced:4 of 4 (100.0%)
Same Version:1 (25.0%)
Same OS:2 (50.0%)
From: petercowburn at gmail dot com Assigned: colder (profile)
Status: Closed Package: SPL related
PHP Version: 5.3.0RC2 OS: OS X
Private report: No CVE-ID: None
 [2009-05-22 10:30 UTC] petercowburn at gmail dot com
Description:
------------
It appears that using PHP5.3.0RC2-dev the SplFileInfo::getPathinfo method just returns the SplFileInfo object on which it was called rather than an SplFileInfo object for its path.



Reproduce code:
---------------
<?php
$info = new SplFileInfo('/usr/bin/php');
$parent_info = $info->getPathInfo();
var_dump($parent_info->getRealPath());
?>

Expected result:
----------------
string(8) "/usr/bin"


Actual result:
--------------
string(12) "/usr/bin/php"

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2009-06-16 22:24 UTC] petercowburn at gmail dot com
I downloaded a recent snap of PHP 5.3 (200906162030) which gives me PHP 5.3.0RC4 and amended the method definition which was using spl_filesystem_object_get_pathname rather than spl_filesystem_object_get_path.  With that function name changed, the call to SplFileInfo::getPathInfo now appears to work as expected from the description given in the documentation.

Reproduce code:
---------------
<?php
$info = new SplFileInfo('/usr/bin/php');
$parent_info = $info->getPathInfo();
var_dump($parent_info->getRealPath());
?>

Expected result:
----------------
string(8) "/usr/bin"

Actual result:
----------------
string(8) "/usr/bin"

Diff file:
----------
Index: spl_directory.c
===================================================================
RCS file: /repository/php-src/ext/spl/spl_directory.c,v
retrieving revision 1.45.2.27.2.23.2.43
diff -u -u -r1.45.2.27.2.23.2.43 spl_directory.c
--- spl_directory.c	4 Jun 2009 14:46:26 -0000	1.45.2.27.2.23.2.43
+++ spl_directory.c	16 Jun 2009 22:13:45 -0000
@@ -1176,7 +1176,7 @@
 
 	if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|C", &ce) == SUCCESS) {
 		int path_len;
-		char *path = spl_filesystem_object_get_pathname(intern, &path_len TSRMLS_CC);
+		char *path = spl_filesystem_object_get_path(intern, &path_len TSRMLS_CC);
 		if (path) {
 			spl_filesystem_object_create_info(intern, path, path_len, 1, ce, return_value TSRMLS_CC);
 		}
 [2009-08-19 15:30 UTC] tomasz dot kotecki at gmail dot com
This could be related... using 5.3.0. Using example from http://uk3.php.net/manual/en/splfileinfo.getpath.php

<?php
$info = new SplFileInfo('/usr/bin/php');
var_dump($info->getPath());


$info = new SplFileInfo('/usr/');
var_dump($info->getPath());?>

expected result:
----------------

string(8) "/usr/bin"
string(4) "/usr"

actual result:
--------------
string(8) "/usr/bin"
string(0) ""
 [2010-01-27 11:08 UTC] weirdan at gmail dot com
Also behavior has changed since 5.2 (where it at least behaved according to documentation):

weirdan@virtual-debian:/home/sam/trunk$ php -r 'var_dump(phpversion());
$f = new SplFileInfo("/usr/bin/php5"); 
$d = $f->getPathInfo(); 
var_dump($d->getRealPath());'

string(8) "5.2.12-2"
string(8) "/usr/bin"

weirdan@virtual-debian:/home/sam/trunk$ sudo update-alternatives --set php /usr/local/php/bin/php # switch to 5.3.1
update-alternatives: using /usr/local/php/bin/php to provide /usr/bin/php (php) in manual mode.

weirdan@virtual-debian:/home/sam/trunk$ php -r 'var_dump(phpversion());
$f = new SplFileInfo("/usr/bin/php5"); 
$d = $f->getPathInfo(); 
var_dump($d->getRealPath());'

string(5) "5.3.1"
string(13) "/usr/bin/php5"

weirdan@virtual-debian:/home/sam/trunk$ ls -l /usr/bin/php5
-rwxr-xr-x 1 root root 5261500 Jan 11 19:36 /usr/bin/php5



The likely cause is the 'fix' for the http://bugs.php.net/bug.php?id=45345 (which should have been rejected as RTFM I believe).
 [2010-04-27 10:56 UTC] colder@php.net
Automatic comment from SVN on behalf of colder
Revision: http://svn.php.net/viewvc/?view=revision&amp;revision=298647
Log: Fixed #48361 (SplFileInfo::getPathName() should return the parent
 [2010-04-27 10:56 UTC] colder@php.net
-Status: Assigned +Status: Closed
 [2010-04-27 10:56 UTC] colder@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/.
 
Thank you for the report, and for helping us make PHP better.


 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Thu Nov 21 11:01:29 2024 UTC