<i id='QXKLv'><tr id='QXKLv'><dt id='QXKLv'><q id='QXKLv'><span id='QXKLv'><b id='QXKLv'><form id='QXKLv'><ins id='QXKLv'></ins><ul id='QXKLv'></ul><sub id='QXKLv'></sub></form><legend id='QXKLv'></legend><bdo id='QXKLv'><pre id='QXKLv'><center id='QXKLv'></center></pre></bdo></b><th id='QXKLv'></th></span></q></dt></tr></i><div id='QXKLv'><tfoot id='QXKLv'></tfoot><dl id='QXKLv'><fieldset id='QXKLv'></fieldset></dl></div>

      1. <tfoot id='QXKLv'></tfoot>

        <small id='QXKLv'></small><noframes id='QXKLv'>

        <legend id='QXKLv'><style id='QXKLv'><dir id='QXKLv'><q id='QXKLv'></q></dir></style></legend>
        • <bdo id='QXKLv'></bdo><ul id='QXKLv'></ul>
      2. PHP 是否在文件处理程序被垃圾收集后关闭文件?

        Does PHP close the file after the file handler is garbage collected?(PHP 是否在文件处理程序被垃圾收集后关闭文件?)
        <legend id='kMUXM'><style id='kMUXM'><dir id='kMUXM'><q id='kMUXM'></q></dir></style></legend>
      3. <i id='kMUXM'><tr id='kMUXM'><dt id='kMUXM'><q id='kMUXM'><span id='kMUXM'><b id='kMUXM'><form id='kMUXM'><ins id='kMUXM'></ins><ul id='kMUXM'></ul><sub id='kMUXM'></sub></form><legend id='kMUXM'></legend><bdo id='kMUXM'><pre id='kMUXM'><center id='kMUXM'></center></pre></bdo></b><th id='kMUXM'></th></span></q></dt></tr></i><div id='kMUXM'><tfoot id='kMUXM'></tfoot><dl id='kMUXM'><fieldset id='kMUXM'></fieldset></dl></div>

                <tbody id='kMUXM'></tbody>
              • <bdo id='kMUXM'></bdo><ul id='kMUXM'></ul>

                  <small id='kMUXM'></small><noframes id='kMUXM'>

                  <tfoot id='kMUXM'></tfoot>

                • 本文介绍了PHP 是否在文件处理程序被垃圾收集后关闭文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  如果我有一个打开文件并读取一行的简短函数,我是否需要关闭文件?或者当执行退出函数并且 $fh 被垃圾收集时,PHP 会自动执行此操作吗?

                  If I have a short function that opens a file and reads a line, do I need to close the file? Or will PHP do this automatically when execution exits the function and $fh is garbage collected?

                  function first_line($file) {
                      $fh = fopen($file);
                      $first_line = fgets($fh);
                      fclose($fh);
                      return $first_line;
                  }
                  

                  可以简化为

                  function first_line($file) {
                      return fgets(fopen($file));
                  }
                  

                  这当然是理论上的,因为这段代码没有任何错误处理.

                  This is of course theoretical right now, as this code doesn't have any error handling.

                  推荐答案

                  一旦对资源的所有引用都被删除,PHP 就会自动运行资源析构函数.

                  PHP automatically runs the resource destructor as soon as all references to that resource are dropped.

                  由于 PHP 具有基于引用计数的垃圾收集,因此您可以相当确定这会尽早发生,在您的情况下,一旦 $fh 超出范围.

                  As PHP has a reference-counting based garbage collection you can be fairly sure that this happens as early as possible, in your case as soon as $fh goes out of scope.

                  在 PHP 5.4 之前 fclose 如果您试图关闭分配了两个以上引用的资源,实际上并没有做任何事情.

                  Before PHP 5.4 fclose didn't actually do anything if you tried to close a resource that had more than two references assigned to it.

                  这篇关于PHP 是否在文件处理程序被垃圾收集后关闭文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                  相关文档推荐

                  DeepL的翻译效果还是很强大的,如果我们要用php实现DeepL翻译调用,该怎么办呢?以下是代码示例,希望能够帮到需要的朋友。 在这里需要注意,这个DeepL的账户和api申请比较难,不支持中国大陆申请,需要拥有香港或者海外信用卡才行,没账号的话,目前某宝可以
                  PHP通过phpspreadsheet导入Excel日期,导入系统后,全部变为了4开头的几位数字,这是为什么呢?原因很简单,将Excel的时间设置问文本,我们就能看到该日期本来的数值,上图对应的数值为: 要怎么解决呢?进行数据转换就行,这里可以封装方法,或者用第三方的
                  mediatemple - can#39;t send email using codeigniter(mediatemple - 无法使用 codeigniter 发送电子邮件)
                  Laravel Gmail Configuration Error(Laravel Gmail 配置错误)
                  Problem with using PHPMailer for SMTP(将 PHPMailer 用于 SMTP 的问题)
                  Issue on how to setup SMTP using PHPMailer in GoDaddy server(关于如何在 GoDaddy 服务器中使用 PHPMailer 设置 SMTP 的问题)
                    <bdo id='U4jxG'></bdo><ul id='U4jxG'></ul>

                      <tfoot id='U4jxG'></tfoot>

                      <legend id='U4jxG'><style id='U4jxG'><dir id='U4jxG'><q id='U4jxG'></q></dir></style></legend>

                      <small id='U4jxG'></small><noframes id='U4jxG'>

                          • <i id='U4jxG'><tr id='U4jxG'><dt id='U4jxG'><q id='U4jxG'><span id='U4jxG'><b id='U4jxG'><form id='U4jxG'><ins id='U4jxG'></ins><ul id='U4jxG'></ul><sub id='U4jxG'></sub></form><legend id='U4jxG'></legend><bdo id='U4jxG'><pre id='U4jxG'><center id='U4jxG'></center></pre></bdo></b><th id='U4jxG'></th></span></q></dt></tr></i><div id='U4jxG'><tfoot id='U4jxG'></tfoot><dl id='U4jxG'><fieldset id='U4jxG'></fieldset></dl></div>
                              <tbody id='U4jxG'></tbody>