包含多个 php 脚本
Include multiple php scrips
我在调用的页面上使用了两个 php 脚本(avatar.php 和 items.php)。在 php 数据的 both 中,我包含了另一个脚本:
include "../site/api-oauth-master/Client.php"; //
include "../site/api-oauth-master/GrantType/IGrantType.php";
include "../site/api-oauth-master/GrantType/AuthorizationCode.php";
我现在得到错误:
Fatal error: Cannot declare class OAuth2\Client, because the name is
already in use in /www/htdocs/xxxx/site/api-oauth-master/Client.php on
line 32
Client.php的第32行是:
class Client
{
/**
* Different AUTH method
*/
const AUTH_TYPE_URI = 0;
const AUTH_TYPE_AUTHORIZATION_BASIC = 1;
const AUTH_TYPE_FORM = 2;
问题很明显是因为 Client.php 脚本被包含了两次。我认为 "include" 这应该不是问题。脚本如何在同一页面上包含两次的任何提示?
使用include_once
或require_once
。
include_once "../site/api-oauth-master/Client.php"; //
include_once "../site/api-oauth-master/GrantType/IGrantType.php";
include_once"../site/api-oauth-master/GrantType/AuthorizationCode.php";
我在调用的页面上使用了两个 php 脚本(avatar.php 和 items.php)。在 php 数据的 both 中,我包含了另一个脚本:
include "../site/api-oauth-master/Client.php"; //
include "../site/api-oauth-master/GrantType/IGrantType.php";
include "../site/api-oauth-master/GrantType/AuthorizationCode.php";
我现在得到错误:
Fatal error: Cannot declare class OAuth2\Client, because the name is already in use in /www/htdocs/xxxx/site/api-oauth-master/Client.php on line 32
Client.php的第32行是:
class Client
{
/**
* Different AUTH method
*/
const AUTH_TYPE_URI = 0;
const AUTH_TYPE_AUTHORIZATION_BASIC = 1;
const AUTH_TYPE_FORM = 2;
问题很明显是因为 Client.php 脚本被包含了两次。我认为 "include" 这应该不是问题。脚本如何在同一页面上包含两次的任何提示?
使用include_once
或require_once
。
include_once "../site/api-oauth-master/Client.php"; //
include_once "../site/api-oauth-master/GrantType/IGrantType.php";
include_once"../site/api-oauth-master/GrantType/AuthorizationCode.php";