0

I´m using on my called page two php scripts (avatar.php and items.php). In both of the php datas i have another scripts included like that:

include "../site/api-oauth-master/Client.php"; // 
include "../site/api-oauth-master/GrantType/IGrantType.php"; 
include "../site/api-oauth-master/GrantType/AuthorizationCode.php"; 

I get now the error:

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

The line 32 of Client.php is:

class Client
{
    /**
     * Different AUTH method
     */
    const AUTH_TYPE_URI                 = 0;
    const AUTH_TYPE_AUTHORIZATION_BASIC = 1;
    const AUTH_TYPE_FORM                = 2;

Obviusly the problem comes because the Client.php script gets included two times. I thought with "include" this shouldn´t be a problem. Any tips how the scripts can inluded two times on the same page?

Kelster
  • 39
  • 5
  • With include you somply take the content of a file and place it in the file where you included it. So you basically have two times declared the class Client -> Yourthought it would work with "include" are wrong. include is noething else than taking the content of a file and place it there where you included it. Like a copy paste. Try to replace `include()` by `require_once()` and it should work I guess. – Twinfriends Feb 27 '18 at 12:31
  • Possible duplicate of [Difference between require, include and require\_once?](https://stackoverflow.com/questions/2418473/difference-between-require-include-and-require-once) – IsThisJavascript Feb 27 '18 at 12:36

1 Answers1

1

Use include_once or 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";

http://php.net/manual/en/function.include-once.php