<object id="xwuag"></object>
      1. <tbody id="xwuag"><pre id="xwuag"><video id="xwuag"></video></pre></tbody>
        <progress id="xwuag"></progress>

        <nav id="xwuag"><big id="xwuag"><rt id="xwuag"></rt></big></nav>
        <em id="xwuag"></em>

        <nav id="xwuag"></nav><rp id="xwuag"></rp>
        <li id="xwuag"></li>
      2. <rp id="xwuag"></rp>
        <s id="xwuag"></s><th id="xwuag"><pre id="xwuag"><video id="xwuag"></video></pre></th>
      3. <nav id="xwuag"><center id="xwuag"></center></nav>
          <dd id="xwuag"><big id="xwuag"></big></dd>

          include_once

          (PHP 4, PHP 5, PHP 7)

          include_once 语句在脚本执行期间包含并运行指定文件。此行为和 include 语句类似,唯一区别是如果该文件中已经被包含过,则不会再次包含。如同此语句名字暗示的那样,只会包含一次。

          include_once 可以用于在脚本执行期间同一个文件有可能被包含超过一次的情况下,想确保它只被包含一次以避免函数重定义,变量重新赋值等问题。

          更多信息参见 include 文档。

          Note:

          在 PHP 4中,_once 的行为在不区分大小写字母的操作系统(例如 Windows)中有所不同,例如:

          Example #1 include_once 在 PHP 4 运行于不区分大小写的操作系统中

          <?php
          include_once "a.php"// 这将包含 a.php
          include_once "A.php"// 这将再次包含 a.php!(仅 PHP 4)
          ?>

          此行为在 PHP 5 中改了,例如在 Windows 中路径先被规格化,因此 C:\PROGRA~1\A.phpC:\Program Files\a.php 的实现一样,文件只会被包含一次。

          add a note add a note

          User Contributed Notes 8 notes

          up
          113
          Greg McCarthy
          2 years ago
          In response to what a user wrote 8 years ago regarding include_once being ran two times in a row on a non-existent file:

          Perhaps 8 years ago that was the case, however I have tested in PHP 5.6, and I get this:

          $result = include_once 'fakefile.php';  // $result = false
          $result = include_once 'fakefile.php'   // $result is still false
          up
          187
          roach dot scott+spam at googlemail dot com
          10 years ago
          If you include a file that does not exist with include_once, the return result will be false.

          If you try to include that same file again with include_once the return value will be true.

          Example:
          <?php
          var_dump
          (include_once 'fakefile.ext'); // bool(false)
          var_dump(include_once 'fakefile.ext'); // bool(true)
          ?>

          This is because according to php the file was already included once (even though it does not exist).
          up
          -13
          xcl_rockman at qq dot com
          4 years ago
          config.php
          <?php
          return array("test">1);

          -------------
          //first
          $config = include_once("config.php");
          var_dump($config);

          $config = include_once("config.php");
          var_dump($config);

          -------------------
          output will be
          array(
             
          "test"=>1,
          )

          nothing
          up
          -12
          sascha dot diebel at gmail dot com
          2 years ago
          i tried

          -------------------------------- index.php:
          $out='todo 1';
          include 'file1.php';
          $out='todo 2';
          include 'file1.php';
          echo 'end';
          -------------------------------- file1.php:
          include_once 'file2.php';
          if(isset($out)){
          echo $out;
          }
          -------------------------------- file2.php:
          $out='first todo once';
          include 'file.php';

          the output is:
          first todo once
          first todo once
          todo 2

          what should i do?

          if i would replace in file2.php include with include_once, then i have following output:
          first todo once
          todo 2

          i could write
          $out='first todo once';
          include 'file1.php'
          $out='todo 1';
          include 'file1.php';
          $out='todo 2';
          include 'file1.php';

          but i don't want :-)
          please help
          up
          -51
          webmaster AT domaene - kempten DOT de
          12 years ago
          Since I like to reuse a lot of code it came handy to me to begin some sort of library that I stored in a subdir
          e.g. "lib"

          The only thing that bothered me for some time was that although everything worked all IDEs reported during editing
          these useless warnings "file not found" when library files included other library files, since my path were given all relative to the corresponding document-root.

          Here is a short workaround that makes that gone:

          <?php
          // Change to your path

          if(strpos(__FILE__,'/lib/') != FALSE){
             
          chdir("..");
          }
          include_once (
          './lib/other_lib.inc');
          // ... or any other include[_once] / require[_once]
          ?>

          just adjust the path and it will be fine - also for your IDE.

          greetings
          up
          -51
          flobee at gmail dot com
          14 years ago
          i already had a discussion with several people about "not shown errors"
          error reporting and all others in php.ini set to: "show errors" to find problems:
          the answer i finally found:
          if you have an "@include..." instead of "include..." or "require..('somthing') in any place in your code
          all following errors are not shown too!!!

          so, this is actually a bad idea when developing because paser errors will be droped too:
          <?php
          if(!@include_once('./somthing') ) {
              echo
          'can not include';
          }
          ?>

          solution:
          <?php
          if(!@file_exists('./somthing') ) {
              echo
          'can not include';
          } else {
             include(
          './something');
          }
          ?>
          up
          -63
          emanuele at rogledi dot com
          11 years ago
          For include_once a file in every paths of application we can do simply this

          include_once($_SERVER["DOCUMENT_ROOT"] . "mypath/my2ndpath/myfile.php");
          up
          -38
          1083706899 at qq dot com
          3 years ago
          require_once() can check the file if once include ,or the file is wrong will tell a error and quit the script.

          備份地址:http://www.lvesu.com/blog/php/function.include-once.php

          国产成人午夜福利r在线观看_欧美性受xxxx孕妇_白丝娇喘过膝袜爽短裙调教_jizz jizz xxxx