0

I noticed my Autoloader was not working properly on destructors (after die;), because PHP changes the current directory on shutting down.

was:

D:\www\arsenal

got changed to:

C:\wamp\bin\apache\Apache2.2.21

I don't even know why it does that. I solved the Autoloader problem using realpath but was wondering what kind of other problems it may cause.

So, is it safe to use chdir to change it back in a function registered with register_shutdown_function? I tested it and totally solved the Autoloader problem, as well as realpath did (the shutdown function gets called before the destructors, don't know why either).

The catch is that i'm afraid of the consequences. I don't even know if PHP behaves this way in other platforms. I would really like to have more information on the subject.

I'm on Windows 7, using WAMP 2.2 (PHP 5.3.8, Apache 2.2.21).

Hugo Mota
  • 11,200
  • 9
  • 42
  • 60
  • Instead of going that route why don't you simply base your paths in the current dir the file is in `__DIR__`? – PeeHaa May 10 '13 at 17:44
  • The `Autoloader`, for instance, has to require files that are not in the library folder itself. So there's no way to use it's location as reference without crippling portability. – Hugo Mota May 10 '13 at 17:47
  • With about injecting the path into the autoloader at construction phase? – PeeHaa May 10 '13 at 17:52
  • I'm not looking for workarounds for the issues (I already solved it without `chdir` as I mentioned). I just wanted to know if it's safe to "normalize" things with `chdir` and more information about this behavior on other platforms. – Hugo Mota May 10 '13 at 17:58

0 Answers0