如何删除包含文件? [英] How to remove an include file?

查看:95
本文介绍了如何删除包含文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的页面中包含两个文件。像这样:

I have two files that are included in my page. Like this:

// mypage.php
include 'script1.php';
include 'script2.php';

我首先需要它们两个,然后我需要删除其中一个,像这样的东西:

I need both of them in first, and then I need to remove one of them, something like this:

if ($var == 'one') {
      // inactive script1.php file
} else {
     // inactive script2.php file
}

这是很难解释为什么我需要暂停其中一个,我只是想知道,我该怎么做?有可能做不像 include

That's hard to explain why I need to inactive one of them, I Just want to know, how can I do that? Is it possible to do unlike include?

推荐答案

简单的答案是不,你不能。

The simple answer is no, you can't.

扩展的答案是,当你运行PHP时,它会进行两次传递。第一遍将PHP编译成机器代码。这是添加 include 的地方。第二遍是从第一遍开始执行代码。由于编译过程是 include 完成的,因此无法在运行时将其删除。

The expanded answer is that when you run PHP, it makes two passes. The first pass compiles the PHP into machine code. This is where includes are added. The second pass is to execute the code from the first pass. Since the compilation pass is where the include was done, there is no way to remove it at runtime.

自你有一个函数碰撞,这里是如何使用对象(类)来解决这个问题

Since you're having a function collision, here's how to get around that using objects(classes)

class Bob {
    public static function samename($args) {

   }
}
class Fred {
   public static function samename($args) {

   }
}

请注意,这两个类都具有 samename( )函数但它们位于不同的类中,因此没有碰撞。因为它们是 static 你可以像这样调用它们

Note that both classes have the samename() function but they live within a different class so there's no collision. Because they are static you can call them like so

Bob::samename($somearghere);
Fred::samename($somearghere);

这篇关于如何删除包含文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆