继承 - 在包含的文件中包含文件

时间:2013-01-16 18:58:51

标签: php inheritance

我有三个文件:

  • blog.php的
  • comment.php
  • function.php

在我的blog.php中,有一个for()for function.php和comment.php。

我的问题是:是否有任何方法可以让comment.php继承blog.php中包含的function.php,并在不声明include()函数的情况下使用其内容?

提前致谢,任何帮助。

2 个答案:

答案 0 :(得分:1)

每次包含文件时,包含的文件都会在包含文件之前继承所有代码。如果你包括这样的东西:

a.php只会

$foo="bar";
include('b.php');

b.php

include('c.php');
$foobar = $bar." is ".$foo

<强> c.php

$bar = "foo";

<强> d.php

include('a.php');
echo $foobar;

希望有所帮助。

答案 1 :(得分:0)

如果首先包含function.php,它将可用于在comment.php中运行的任何代码。

但是,如果comment.php要求function.php正常运行,那么将include_once放在comment.php的顶部是个好主意。