|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #30210 Destructor resetting working-directory
Submitted: 2004-09-23 16:31 UTC Modified: 2004-09-23 20:27 UTC
From: m dot leuffen at i-line dot net Assigned:
Status: Not a bug Package: Directory function related
PHP Version: 5.0.1 OS: Linux
Private report: No CVE-ID: None
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
Block user comment
Status: Assign to:
Bug Type:
From: m dot leuffen at i-line dot net
New email:
PHP Version: OS:


 [2004-09-23 16:31 UTC] m dot leuffen at i-line dot net

In __destruct() function the working-directory is default set to root ('/').


Reproduce code:
class Test {
  public function __construct() {
    echo "Constructor: ".getcwd();
  public function __destruct() {
    echo "\nDestructor: ".getcwd();
$obj = new Test();

Expected result:
Constructor: /home/xyz/dir
Destructor: /home/xyz/dir

Actual result:
Constructor: /home/xyz/dir
Destructor: /


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2004-09-23 20:27 UTC]
Thank you for taking the time to write to us, but this is not
a bug. Please double-check the documentation available at and the instructions on how to report
a bug at

The destructor is called during shutdown. If you require certain behavior the unset() your object before the script terminates.
 [2011-05-24 13:31 UTC] pinaki17 at gmail dot com
I know this is a old thread but the issue still exists. How can this possibly be not a bug? The current working directory is where all the include file dependencies are related to. How would you justify resetting it? Also what logic goes behind it? As i understand, i can set the working directory again in the destructor and write the code and all these objects will be gc'ed once the page dies, so why have the reset happen before the destructor?
 [2011-05-25 13:10 UTC] olafurw at gmail dot com
This has been fixed in newer versions of PHP. Works in 5.2.6 and 5.3.5 at least.
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Thu Apr 25 01:01:30 2024 UTC