您好,欢迎来到三六零分类信息网!老站,搜索引擎当天收录,欢迎发信息

关于PHP的析构函数问题

2024/6/22 14:19:24发布39次查看
直接上代码
class filetest extends splfileinfo{ public function __destruct(){ var_dump($this->getrealpath()); }}$file = new filetest('index.php'); //boolean falsenew filetest('index.php'); //'e:\apache24\htdocs\index.php'

如以上代码所示,同样new一个对象,赋值给变量和没赋值给变量结果却不一样,有人知道原因吗?
回复内容: 直接上代码
class filetest extends splfileinfo{ public function __destruct(){ var_dump($this->getrealpath()); }}$file = new filetest('index.php'); //boolean falsenew filetest('index.php'); //'e:\apache24\htdocs\index.php'

如以上代码所示,同样new一个对象,赋值给变量和没赋值给变量结果却不一样,有人知道原因吗?
我在php5.6下跑出的结果:
d:\php5.6\php.exe e:\m5\carvincai\test\file.phpbool(false)bool(false)
能不能再提供一些更详细的信息?
更新:
我修改了一下代码:
getrealpath()); }}$file = new filetest(__file__); //boolean falsenew filetest(__file__); //'e:\apache24\htdocs\index.php'
结果:
d:\php5.6\php.exe e:\m5\carvincai\test\file.phpstring(29) e:\m5\carvincai\test\file.phpstring(29) e:\m5\carvincai\test\file.php
题主你是不是可以再检查一下构造函数里传入的文件名?
php 5.6 环境没问题,结果一致
首先要确保 'index.php' 文件是存在的
你肯定是在同一个环境下面执行了,使用了 'index.php' 作为参数传入的?
该用户其它信息

VIP推荐

免费发布信息,免费发布B2B信息网站平台 - 三六零分类信息网 沪ICP备09012988号-2
企业名录 Product