全局并包含在PHP中

时间:2015-04-13 09:54:50

标签: php include global require bootstrapping

我有一个引导脚本。

bootstrap.php中

<?php
  $bootstrapFoo = 'foo';

和主要脚本。

main.php

<?php
  require_once 'bootstrap.php';
  print $bootstrapFoo; // this is working

  // I include a subscript
  include_once 'subscript.php';

subscript.php

<?php
  print $bootstrapFoo; // this is NOT working.

我的解决方案:

<?php
  global $bootstrapFoo;
  print $bootstrapFoo; // now that's working
  

这是正确的方法吗?

ps:找不到重复项。

0 个答案:

没有答案