|  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
Anyone can comment on a bug. Have a simpler test case? Does it work for you on a different platform? Let us know!
Just going to say 'Me too!'? Don't clutter the database with that please !
Your email address:
Solve the problem:
15 - 4 = ?
Subscribe to this entry?

 [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: Mon Apr 22 03:01:32 2024 UTC