What is the scope of require_once in PHP?

后端 未结 4 1609
故里飘歌
故里飘歌 2021-01-08 01:08

Simple question: Is the scope of require_once global?

For example:



        
4条回答
  •  一个人的身影
    2021-01-08 01:44

    At least in PHP 7.3, require_once has global scope.
    If it would not, both x.php and z.php should throw errors as y.php does:

    a.php

    b.php


    x.php

    -->

    #0 c() called at [/var/www/b.php:2]  
    #1 b() called at [/var/www/a.php:3]  
    #0 c() called at [/var/www/a.php:4]  
    

    y.php

    --> Fatal error: Uncaught Error: Call to undefined function b() in /var/www/y.php on line 3

    z.php

    -->

    #0 b() called at [/var/www/z.php:4]
    

提交回复
热议问题