php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Request #53787 Add support for chdir() without any parameter called
Submitted: 2011-01-19 13:28 UTC Modified: 2011-01-19 13:47 UTC
From: rzufall36 at yahoo dot com Assigned:
Status: Wont fix Package: Directory function related
PHP Version: Irrelevant OS: Ubuntu 10.04
Private report: No CVE-ID: None
Have you experienced this issue?
Rate the importance of this bug to you:

 [2011-01-19 13:28 UTC] rzufall36 at yahoo dot com
Description:
------------
For consistency with the widely known 'cd' tool and existing functionality from 
other programming languages, e.g. Perl, I believe that a call to the chdir() 
function without any parameters should be supported. In Bash and Perl, cd/chdir 
without any parameters given, changes back to the home directory of the user. As 
this is pretty convenient (because you usually start in the home directory and 
can then easier get back), I believe that such a change would also be pretty 
useful within PHP.

Test script:
---------------
# dummy script, no useful functionality
# to be executed from command line

echo "Write something:\n";
$string = trim(fgets(STDIN));
chdir('somedir');
file_put_contents('file', $string);
chdir() 
file_put_contents('file', $string);

# or just simply on the command line
php -r 'chdir();'

Expected result:
----------------
There should be no PHP warning (obviously), we should change back to the user's 
home directory and the last line

    file_put_contents('file', $string);

should then write the $string variable to /home/johndoe/file

Actual result:
--------------
$string is written to /home/johndoe/somedir/file (just as expected), however 
chdir() gives a PHP Warning:  chdir() expects exactly 1 parameter, 0 given and 
aborts the programm.

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2011-01-19 13:47 UTC] pajoye@php.net
-Status: Open +Status: Wont fix
 [2011-01-19 13:47 UTC] pajoye@php.net
chdir maps posix chdir, not Bash (or some other shells) specific features.
 
PHP Copyright © 2001-2019 The PHP Group
All rights reserved.
Last updated: Thu Jul 18 07:01:26 2019 UTC