What does the dot-slash do to PHP include calls?

前端 未结 7 1488
隐瞒了意图╮
隐瞒了意图╮ 2020-12-01 09:05

A. What does this do?

require (\"./file.php\");

B. in comparison to this?

require (\"file.php\");

(

7条回答
  •  无人及你
    2020-12-01 09:26

    The first version forces the internal mechanism to include files relatively to the... directly executed file. So for example you have

    index.php

    // directly executed script (php -f index.php or from a browser)
    include 'second.php';
    

    second.php

    // This is included relatively to index.php
    // Actually, it is first searched relatively to include_path, then relatively
    // to index.php
    include './third.php';
    

    third.php

    // This is included relatively to second.php ONLY. It does not search
    // include_path
    return "foo";
    

提交回复
热议问题