【问题标题】:php __destruct why get different result by file_get_contentsphp __destruct 为什么通过 file_get_contents 得到不同的结果
【发布时间】:2021-05-05 06:56:52
【问题描述】:

hint.php 中的内容是“111”

<?php

class T{
    public $filename = "hint.php";

    function __destruct() {
        var_dump(file_get_contents($this->filename));
    }
}

new T();

得到了

string(3) "111"

而当我设置一个变量$t时,结果会不一样。

$t = new T();

得到了

string(0) ""

为什么会这样

【问题讨论】:

  • 我无法重现您的结果。设置$t = new T();我仍然得到我的hint.php的内容。
  • 我的php版本是PHP Version 7.3.1 系统是windows

标签: php php-7


【解决方案1】:

这是由bug in PHP 引起的。它已经存在了很长时间,而且看起来不会很快修复。

为避免此问题,请勿在关闭脚本中使用相对路径。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2018-09-06
    • 1970-01-01
    • 1970-01-01
    • 2021-12-15
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多