[英]PHP Fake require_once to always return true
Is it possible to "fake" the inclusion of a file ? 是否可以“伪造”包含文件?
I am testing a code base where DI hasn't been implemented and want to include a class file with my own version before it gets required. 我正在测试尚未实现DI的代码库,并希望在需要它之前包含具有自己版本的类文件。 When it hits the actual require line, I get complaints about the class already being added.
当它达到实际需求行时,我会抱怨已经添加了该类。
So when I do require_once
on the file, I don't want to actually include it, but it to carry on like it did. 因此,当我在文件上执行
require_once
时,我实际上并不希望包含它,而是像它一样继续进行。
您可以使用include_once()
,它不会给您造成严重错误,但仍会尝试包含该文件。
My solution was to duplicate the project and change directory before including the configuration files containing require statements: except in the copied directory, the files were empty. 我的解决方案是在包含包含require语句的配置文件之前复制项目并更改目录:除了在复制的目录中之外,这些文件为空。 Then I switched back to the current directory.
然后我切换回当前目录。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.