Giving PHP include()'d files parent variable scope

后端 未结 2 1168
夕颜
夕颜 2021-01-05 00:19

Is there anyway to for an included file to be used in a parent scope to the one it was called in? The following example is simplified, but does the same job.

In esse

2条回答
  •  栀梦
    栀梦 (楼主)
    2021-01-05 01:19

    The only way I know how to is to use the superglobal array.

    main.php:

      $GLOBALS['myVar'] = 'something bar foo';
    
      $success = myPlugin('included.php');
    
      if($success)
      {
        echo $GLOBALS['myResult'];
      }
    

    included.php:

提交回复
热议问题