簡體   English   中英

繼承-將文件包含在包含文件中

[英]Inheritance - Include files in an included file

我有三個文件:

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

在我的blog.php內,有一個function.php和comment.php的include()。

我的問題是:comment.php有什么方法可以從blog.php繼承function.php的包含內容,並使用其內容而無需再次聲明include()函數?

在此先感謝您的幫助。

每次包含文件時,所包含的文件都會在包含之前繼承所有代碼。 如果包含以下內容:

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;

希望有點幫助。

如果首先包含function.php,則它將對comment.php中運行的任何代碼可用。

但是,如果comment.php要求function.php能夠正確運行,則在include_once的頂部放置comment.php是一個好主意。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM