php.net |  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
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
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
Description:
------------
Hi.

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

Bye,
  Matthias



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: /

Patches

Pull Requests

History

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

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: Sat Dec 21 17:01:58 2024 UTC