4

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.

5
  • 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 again Commented 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. Commented May 25, 2011 at 11:10
  • A "random" string? You mean arbitrary? And are you sure? That sounds very wrong. Commented May 25, 2011 at 11:17
  • @tomalak - yes, the random string turns out to be a valid path but it is random certainly. Commented 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? Commented May 25, 2011 at 12:56

3 Answers 3

1

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.

Sign up to request clarification or add additional context in comments.

3 Comments

I just noticed that they changed their minds after you poked the bug report thread. Hehe.
Curiously though, they've marked the status as 'Bogus'. Maybe the fix was unintentional
that's me commenting on the bug stating that it works in newer versions. I'm no php dev.
1

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

Tried on PHP 5.3.2 and PHP 5.3.4 and they both show the expected behavior.
0

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)

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.