为什么getcwd()在__destruct()中返回/? [英] Why does getcwd() returns / in __destruct()?

查看:136
本文介绍了为什么getcwd()在__destruct()中返回/?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我刚刚注意到,如果在__destruct()魔术函数中调用getcwd()则返回"/",而在其他任何方法中,它均返回预期的路径.

I have just noticed that getcwd() return "/" if called within __destruct() magic function, while in any other method it returns the expected path.

您对此有解释吗?

推荐答案

这是SAPI的行为

在脚本关闭期间调用的析构函数已经发送了HTTP标头.在脚本关闭阶段,某些SAPI(例如Apache)的工作目录可能会有所不同."

"Destructors called during the script shutdown have HTTP headers already sent. The working directory in the script shutdown phase can be different with some SAPIs (e.g. Apache)."

来自 http://php.net/manual/en/language.oop5 .decon.php

但是,正如其他答案中提到的那样,有很多方法可以获取当前的相对路径.如果您在运行时更改了它,请确保注意该对象内部的某个地方.

But as mentioned in other answers there are plenty ways to get the current relative path. If you changed it during runtime make sure to note somewhere inside the object.

这篇关于为什么getcwd()在__destruct()中返回/?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆