它们之间有什么区别吗?使用它们是一个偏好的问题?使用一个优于另一个产生任何优势吗?哪个更安全?
PHP中的"include_once"和"require_once"有什么区别?
include_once "connect_to_mysql.php";
require_once "connect_to_mysql.php";
Run Code Online (Sandbox Code Playgroud)
这些之间有什么区别吗?
有谁知道为什么我的require_once()或die(); 不管用.它始终显示致命错误,而不是我键入die()的错误消息.请参阅下面的代码:
require_once ('abc.php') or die("oops");
Run Code Online (Sandbox Code Playgroud)
错误信息显示如下
"致命错误:controller :: require_once()[function.require]:打开所需的'1'失败(include_path ='....."
而不是我键入的消息("oops").
我是第一次编写PHP应用程序(玩具和练习除外),我很难理解为什么PHP包含一个include和一个require构造.
在你写一个解释两者之间差异的答案之前,让我首先说我确实理解了差异 - include产生警告并继续前进,并require产生致命错误.我的问题是:你想什么时候包括,但不需要文件?
也许这对我来说是想象力的失败,但我的应用程序中似乎没有任何文件,如果他们不在那里我不想尖叫.奇怪的是,这并没有让我想要使用,require因为它似乎无法正确处理失败require,所以我使用了一个帮助函数(警告:空气代码):
public static function include($filename) {
if (is_readable($filename)) {
if (!@include($filename)) {
throw new FileNotFoundException("File deleted after readable check");
}
} else {
throw new FileNotFoundException("File missing or unreadable");
}
}
Run Code Online (Sandbox Code Playgroud)
我想我要问的是:
我正在使用NuSOAP尝试使用Java构建的Web服务.到目前为止我有这个代码:
<?php
require_once('lib/nusoap.php');
$wsdl="http://localhost:8080/HelloWorldWS/sayHiService?WSDL";
$client=new nusoap_client($wsdl, 'wsdl');
$param='John';#array('name'=>'John');
echo $client->call('Hey', $param);
unset($client);
?>
Run Code Online (Sandbox Code Playgroud)
但是当网页加载时,我得到一个空白页面甚至没有代码,我真的不知道为什么.难道我做错了什么?
其中include,include_once,require和require_once我一直只使用require_once。许多第三方框架也都使用require_once。
有人可以描述必须使用其他构造的真实情况吗?
require和require_once之间的区别.我只是想知道差异而不是php中的警告和致命错误.
我需要在整个代码中多次包含对另一个php文件example.php的引用,但是我得到"PHP致命错误:无法重新声明类错误".
<?php include 'example.php'; ?>
Run Code Online (Sandbox Code Playgroud)
怎么做到这一点?
require("file.php");
require_once("file.php");
Run Code Online (Sandbox Code Playgroud)
两者都包含所需的文件,如果找不到文件或存在任何其他问题,则会出现致命错误。如果发生错误,两者都会停止执行。
这两个函数有什么区别?
例如,如果我有:
header part(header.php)
footer part(footer.php)
list of functions (functions.php)
list of constants (constants.php)
connect to database part(connection.php)
footer part + close the connection part(footer.php)
Run Code Online (Sandbox Code Playgroud)
在这些例子中我应该使用include,require或者require_once请注意为什么?