Getting around the user class redeclaration issue ?

Discussion forum for MOD Writers regarding MOD Development.
Locked
noverflow
Registered User
Posts: 10
Joined: Mon Jan 13, 2003 6:08 am
Location: Providence
Contact:

Getting around the user class redeclaration issue ?

Post by noverflow » Sun May 01, 2011 12:33 am

Im trying to figure any way possible to access the phpbb session without running into a redeclaration user class issue with my other software im trying to integrate it with.

In this topic ( http://www.phpbb.com/community/viewtopi ... &t=2091861 ) Sam recommended creating a php interface file like so

Code: Select all

<?php
include $phpbb_root_path . 'common.' . $phpEx;

class phpbb
{
    public static $user;
    public static $db;
    [...]
    
    public static function init()
    {
        global $user, $db;
        
        self::$user = &$user;
        self::$db = &$db;
    }
}

phpbb::init();

unset($user, $db); 

My issue is... how can you use this without including the file, that then includes common.php, declaring the user class, and causing the issue?


I tried this as a test, but no luck. - I get the same error. But im sure Sam knew what we was talking about, I just can't figure it out.

Code: Select all



class phpbb{
    public static $user;
    public static $db;
    
    public static function init(){
       
       global $phpbb_root_path;
       global $user, $db;
       
       $phpbb_root_path = './forum/';
       $phpEx = substr(strrchr(__FILE__, '.'), 1);
       define('IN_PHPBB', true);
       include_once('./forum/common.php');
        
        self::$user = &$user;
        self::$db = &$db;
    }
}


phpbb::init();
print_r(phpbb::$user);


unset($user, $db);



class user{



}




Paul
Infrastructure Team Leader
Infrastructure Team Leader
Posts: 25180
Joined: Sat Dec 04, 2004 3:44 pm
Location: The netherlands.
Name: Paul Sohier
Contact:

Re: Getting around the user class redeclaration issue ?

Post by Paul » Sun May 01, 2011 8:56 am

If you get a class redeclaration error you will need to rename the class, doing magic with variables and static classes will not help at all ;)
Knock knock
Race condition
Who's there?

My BlogMy Photosmy phpBB Extensionscustom phpBB work & Development

noverflow
Registered User
Posts: 10
Joined: Mon Jan 13, 2003 6:08 am
Location: Providence
Contact:

Re: Getting around the user class redeclaration issue ?

Post by noverflow » Sun May 01, 2011 1:11 pm

Figured it was too good to be true.
But I actually did get around it at about 2am last night.

I am using the session integration http://www.phpbb.com/kb/article/phpbb3- ... tegration/

What I did was a simple modification to common.php and to sessions.php and just had it name the user class to phpbb_user ONLY when it was requested by mediawiki.

Then just used define('FROM_MEDIAWIKI', true); in my integration code.

astrip
Registered User
Posts: 2
Joined: Mon Mar 26, 2012 8:16 am

Re: Getting around the user class redeclaration issue ?

Post by astrip » Mon Mar 26, 2012 8:56 am

noverflow wrote: What I did was a simple modification to common.php and to sessions.php and just had it name the user class to phpbb_user ONLY when it was requested by mediawiki.
Hi,

I'm facing the same problem at the moment.. Could you provide please the changes you made to common.php and sessions.php to rename the user class?

Thanks a lot

astrip
Registered User
Posts: 2
Joined: Mon Mar 26, 2012 8:16 am

Re: Getting around the user class redeclaration issue ?

Post by astrip » Mon Mar 26, 2012 12:02 pm

I might have found a useful link here:
http://www.mediawiki.org/wiki/Extension ... common.php

bildr
Registered User
Posts: 8
Joined: Sun Mar 14, 2010 2:04 pm

Re: Getting around the user class redeclaration issue ?

Post by bildr » Mon Mar 26, 2012 12:05 pm

:D That is exactly how I did it... I wrote that.
astrip wrote:I might have found a useful link here:
http://www.mediawiki.org/wiki/Extension ... common.php

Locked

Return to “[3.0.x] MOD Writers Discussion”