I have found this http://bugs.php.net/bug.php?id=30210, which according to the PHP team isn't a bug. What I fail to understand is why would you have the directory reset happen before the destructor. Would appreciate your views on the same and also if you can explain the behaviour compared to other languages.
-
could it be that getcwd() is set when its first called then the destructor resets it to null not resetting it as if it was called againLawrence Cherone– Lawrence Cherone2011-05-25 11:06:48 +00:00Commented May 25, 2011 at 11:06
-
nope, there isn't any getcwd() calls in the code at all. the cwd i am expecting is . (i.e. the current working folder) and PHP tends to set it to a random string.pinaki– pinaki2011-05-25 11:10:51 +00:00Commented May 25, 2011 at 11:10
-
A "random" string? You mean arbitrary? And are you sure? That sounds very wrong.Lightness Races in Orbit– Lightness Races in Orbit2011-05-25 11:17:46 +00:00Commented May 25, 2011 at 11:17
-
@tomalak - yes, the random string turns out to be a valid path but it is random certainly.pinaki– pinaki2011-05-25 11:56:17 +00:00Commented May 25, 2011 at 11:56
-
Arbitrary. And if it's a valid path then it's almost certainly not arbitrary. And what is it? And what PHP version? And can you provide a testcase? When is the destructor invoked? Manually during script execution, or as the script is winding down?Lightness Races in Orbit– Lightness Races in Orbit2011-05-25 12:56:10 +00:00Commented May 25, 2011 at 12:56
3 Answers
which according to the PHP team isn't a bug
The bug report you linked to shows that they eventually changed their minds.
This has been fixed in newer versions of PHP. Works in 5.2.6 and 5.3.5 at least.
3 Comments
Upgrade your PHP version perhaps? PHP 5.3.5 does this correctly, your testscript outputs the output you expect. That said; I would argue this indeed is a bug, as I can imagine you might want to clean up stuff in the current working directory while destructing an object, and you would need the CWD to do so.
1 Comment
For a fix, look at http://www.php.net/manual/en/language.oop5.decon.php#56996
I know nothing about pHP internals, so i might be wrong here, but i'm assuming this happens because PHP runs as a module, not as a CGI app (as other languages do). And i'm assuming that the module handling consists in something like:
load_module(php)
init_module(mod_php)
parse&execute_scripts(php)
deinit_module(php)
I'm assuming here that the destructors are executed in the deinit phase, after the parse&exec was done, and all output was already officially done...
Please be careful about the used sapi when testing (php has lots of sapi's)