php 文件显示来自不同文件的输出
php file showing output from a different file
我对 PHP 编程还很陌生。我试图在 Drupal 中编写此自定义 php 代码并看到这种奇怪的行为。基本上我有两个用户可以点击的 php 文件,第一个 php 文件显示第二个文件的输出。我没有在第一个文件中包含(包含)第二个文件。
Home.php - 第一个文件(最后输出'why am i executing')
<?php include 'HomeView.BL.inc';
//Other links to access second file
?>
HomeView.BL.inc
<?php
include 'db.inc';
include 'dao.inc'; - has a class called IDA_Map
?>
FacultyInternshipDetail.php - 第二个文件
<?php
include 'InternshipDetailView.BL.inc';
?>
InternshipDetailView.BL.inc
<?php
echo "why am i executing";
include 'db.inc';
include 'dao.inc';
?>
除了第二个文件的输出,我还看到这个错误 - 无法重新声明 class IDA_Map.
我在其他帖子中读到过关于 'include_once' 但没想到会出现重新声明错误,因为 class (IDA_Map) 每个请求只声明一次。
谢谢。
将所有这些翻转为 require_once
。
<?php require_once'HomeView.BL.inc';
//Other links to access second file
?>
HomeView.BL.inc
<?php
require_once'db.inc';
require_once'dao.inc'; - has a class called IDA_Map
?>
FacultyInternshipDetail.php
<?php
require_once'InternshipDetailView.BL.inc';
?>
InternshipDetailView.BL.inc
<?php
echo "why am i executing";
require_once'db.inc';
require_once'dao.inc';
?>
当您尝试包含同一文件两次时,包含中断。
还要查找 composer 并使用 php 框架,这样您就不必担心这些!
我对 PHP 编程还很陌生。我试图在 Drupal 中编写此自定义 php 代码并看到这种奇怪的行为。基本上我有两个用户可以点击的 php 文件,第一个 php 文件显示第二个文件的输出。我没有在第一个文件中包含(包含)第二个文件。
Home.php - 第一个文件(最后输出'why am i executing')
<?php include 'HomeView.BL.inc';
//Other links to access second file
?>
HomeView.BL.inc
<?php
include 'db.inc';
include 'dao.inc'; - has a class called IDA_Map
?>
FacultyInternshipDetail.php - 第二个文件
<?php
include 'InternshipDetailView.BL.inc';
?>
InternshipDetailView.BL.inc
<?php
echo "why am i executing";
include 'db.inc';
include 'dao.inc';
?>
除了第二个文件的输出,我还看到这个错误 - 无法重新声明 class IDA_Map.
我在其他帖子中读到过关于 'include_once' 但没想到会出现重新声明错误,因为 class (IDA_Map) 每个请求只声明一次。
谢谢。
将所有这些翻转为 require_once
。
<?php require_once'HomeView.BL.inc';
//Other links to access second file
?>
HomeView.BL.inc
<?php
require_once'db.inc';
require_once'dao.inc'; - has a class called IDA_Map
?>
FacultyInternshipDetail.php
<?php
require_once'InternshipDetailView.BL.inc';
?>
InternshipDetailView.BL.inc
<?php
echo "why am i executing";
require_once'db.inc';
require_once'dao.inc';
?>
当您尝试包含同一文件两次时,包含中断。 还要查找 composer 并使用 php 框架,这样您就不必担心这些!