如何在 PHP 中导入库
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/6191873/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to import libraries in PHP
提问by Tarik
I am normally an ASP.NET developer who wants to migrate to PHP. I am taking quite a time to learn it and I am wondering how to use libraries in PHP?
我通常是想要迁移到 PHP 的 ASP.NET 开发人员。我花了很长时间来学习它,我想知道如何在 PHP 中使用库?
Do I need to use require
or include
to import a library into my project to use the classes
, functions
etc. defined in the library? Or something else.
我是否需要使用require
或include
导入库到我的项目使用classes
,functions
等在库中定义?或者是其他东西。
I running PHP on the Apache web server what I've found is for Zend Server and it looked weird to me.
我在 Apache Web 服务器上运行 PHP,我发现它适用于 Zend Server,对我来说它看起来很奇怪。
Can someone explain me overall steps to import and start using libraries in my own code?
有人可以向我解释在我自己的代码中导入和开始使用库的总体步骤吗?
Thanks.
谢谢。
回答by dynamic
You can use both.
您可以同时使用两者。
Require will throw a fatal error if the file is not found.
如果找不到文件,Require 将抛出一个致命错误。
require('lib.class.php');
You could use include if you need to continue the script even if the file couldn't get loaded.
如果您需要继续执行脚本,即使文件无法加载,您也可以使用 include。
Like:
喜欢:
if (!include('lib')) {
doWhatever();
}