|  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
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));
file_put_contents('file', $string);
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.


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2011-01-19 13:47 UTC]
-Status: Open +Status: Wont fix
 [2011-01-19 13:47 UTC]
chdir maps posix chdir, not Bash (or some other shells) specific features.
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sun Apr 21 20:01:32 2024 UTC