phpBB

Development Discussion Board

phpBB's testing ground of bleeding edge code
Advanced search

[RFC] Improve embedding through prefixing names

Publish your own request for comments or patches for the next version of phpBB. Discuss the contributions and proposals of others. Upcoming releases are 3.1/Ascraeus and 3.2/Arsia.

[RFC] Improve embedding through prefixing names

Postby naderman » Mon Jan 30, 2012 7:57 am

One of the problems with embedding phpBB in Drupal, is that both define a function called user_add. To avoid these problems in the future, we should compile a list of function names likely to conflict and do the following with them:
  • Rename the function to include a phpbb_ prefix
  • Change all calls to the method in core code to use phpbb_
  • Add a conditional function definition of the old function name to keep MODs working:
    Code: Select all
    if (!function_exists('user_add'))
    {
        function user_add()
        {
            return call_user_func_array('phpbb_user_add', func_get_args());
        }
    }

This way, most boards with MODs will continue to work. If you require compatability with 3rd party software, you will have to use compatible MODs too.

In addition we might want to encourage MODs to move to the new function names, by throwing E_NOTICE in the compatability function in debug mode. Thoughts on this?
www.naderman.de
Move your forum to Forumatic - we'll take care of maintenance & spam
User avatar
naderman
Development Team Leader
Development Team Leader
 
Posts: 1650
Joined: Sun Jan 11, 2004 2:11 am
Location: Karlsruhe, Germany

Re: [RFC] Improve embedding through prefixing names

Postby imkingdavid » Mon Jan 30, 2012 3:44 pm

Because most MODs will likely break (afaik) between 3.0 and 3.1, why not just go ahead and rename such "problem" functions to include the phpbb_ prefix by default without worrying about MOD breakage?

EDIT:
This way, most boards with MODs will continue to work. If you require compatability with 3rd party software, you will have to use compatible MODs too.

In addition we might want to encourage MODs to move to the new function names, by throwing E_NOTICE in the compatability function in debug mode. Thoughts on this?

Yes. We could require MODs that add new functions in the global scope to prefix them with phpbb_%mod%_ (where %mod%) is a "short name" for the MOD.

Coincidentally, I have been looking at drupal recently and have been doing some initial work on a small drupal module (aka extension). The way they do their hooks in they require a file in drupal/sites/all/modules/ that is module_name.module. Any function in that file that is prefixed with module_name_ and is found as a hook is then called in the main program. (for instance, if a hook called "foobar" is called, it will search enabled modules for functions called %module_name_%foobar).

At the very least, we could require MODs and extensions in 3.1 to require some sort of prefix, whether phpbb_ and the mod short name or just one or the other, to prevent compatibility issues.
I do custom MODs. PM for a quote!
View My: MODs | Portfolio
Please do NOT contact for support via PM or email.
Remember, the enemy's gate is down.
User avatar
imkingdavid
Development Team
Development Team
 
Posts: 902
Joined: Thu Jul 30, 2009 12:06 pm

Re: [RFC] Improve embedding through prefixing names

Postby MichaelC » Mon Jan 30, 2012 4:29 pm

I thought all functions were being renamed in 3.1 to have a phpbb_ prefix?

And as ikd said, all MODs will need a lot of changes to work with hooks, extensions etc. so I wouldn't have though breaking MODs was a worry?

imkingdavid wrote:Yes. We could require MODs that add new functions in the global scope to prefix them with phpbb_%mod%_ (where %mod%) is a "short name" for the MOD.

+1
Unknown Bliss
psoTFX wrote:I went with Olympus because as I said to the teams ... "It's been one hell of a hill to climb"

No unsolicited PMs please except for quotes.
User avatar
MichaelC
Website Team
Website Team
 
Posts: 797
Joined: Thu Jan 28, 2010 6:29 pm

Re: [RFC] Improve embedding through prefixing names

Postby imkingdavid » Mon Jan 30, 2012 4:30 pm

Unknown Bliss wrote:I thought all functions were being renamed in 3.1 to have a phpbb_ prefix?

Only new ones, so far.

EDIT: As an alternative, and this may be too big of a change for 3.1, but I think I remember reading that 3.2 is going to require PHP 5.3. So we could implement namespaces and remove the possibility of conflicts.
I do custom MODs. PM for a quote!
View My: MODs | Portfolio
Please do NOT contact for support via PM or email.
Remember, the enemy's gate is down.
User avatar
imkingdavid
Development Team
Development Team
 
Posts: 902
Joined: Thu Jul 30, 2009 12:06 pm

Re: [RFC] Improve embedding through prefixing names

Postby MichaelC » Mon Jan 30, 2012 4:37 pm

imkingdavid wrote:
Unknown Bliss wrote:I thought all functions were being renamed in 3.1 to have a phpbb_ prefix?

Only new ones, so far.

EDIT: As an alternative, and this may be too big of a change for 3.1, but I think I remember reading that 3.2 is going to require PHP 5.3. So we could implement namespaces and remove the possibility of conflicts.


From the looks of what I can see so far, 3.2 has less changes that affect modifications so maybe it would be better to have all the biggest changes for mod authors in 3.1?
Unknown Bliss
psoTFX wrote:I went with Olympus because as I said to the teams ... "It's been one hell of a hill to climb"

No unsolicited PMs please except for quotes.
User avatar
MichaelC
Website Team
Website Team
 
Posts: 797
Joined: Thu Jan 28, 2010 6:29 pm

Re: [RFC] Improve embedding through prefixing names

Postby brunoais » Mon Jan 30, 2012 8:59 pm

Well... I never liked the namespacing feature in PHP. It does not seem to addup with the rest of the php programming concept. I don't know how to explain this better, though.
brunoais
Registered User
 
Posts: 626
Joined: Fri Dec 18, 2009 3:55 pm

Re: [RFC] Improve embedding through prefixing names

Postby callumacrae » Mon Jan 30, 2012 9:23 pm

imkingdavid wrote:EDIT: As an alternative, and this may be too big of a change for 3.1, but I think I remember reading that 3.2 is going to require PHP 5.3. So we could implement namespaces and remove the possibility of conflicts.

-1, leave it for 4.0: too big a change
"In JavaScript, there is a beautiful, elegant, highly expressive language that is buried under a steaming pile of good intentions and blunders"
—Douglas Crockford

View my MOD, phpBB Mobile
User avatar
callumacrae
Website Team
Website Team
 
Posts: 883
Joined: Tue Apr 27, 2010 9:37 am
Location: England

Re: [RFC] Improve embedding through prefixing names

Postby imkingdavid » Mon Jan 30, 2012 9:32 pm

callumacrae wrote:
imkingdavid wrote:EDIT: As an alternative, and this may be too big of a change for 3.1, but I think I remember reading that 3.2 is going to require PHP 5.3. So we could implement namespaces and remove the possibility of conflicts.

-1, leave it for 4.0: too big a change

Fair enough, just tossing around the idea.

In any case, I think it would be reasonable to require MODs to use either phpbb_%mod%_ or just phpbb_ for functions in global scope and classes, and to prefix most/all phpBB functions with phpbb_, as is already required for new functions, for 3.1. If we can get it done for 3.1, it won't be as big of a headache for 3.2, eh?

EDIT: Ticket
I do custom MODs. PM for a quote!
View My: MODs | Portfolio
Please do NOT contact for support via PM or email.
Remember, the enemy's gate is down.
User avatar
imkingdavid
Development Team
Development Team
 
Posts: 902
Joined: Thu Jul 30, 2009 12:06 pm

Re: [RFC] Improve embedding through prefixing names

Postby MichaelC » Mon Jan 30, 2012 11:35 pm

So all or some of the functions?
Unknown Bliss
psoTFX wrote:I went with Olympus because as I said to the teams ... "It's been one hell of a hill to climb"

No unsolicited PMs please except for quotes.
User avatar
MichaelC
Website Team
Website Team
 
Posts: 797
Joined: Thu Jan 28, 2010 6:29 pm


Return to [3.x] RFCs

Who is online

Users browsing this forum: Bing [Bot] and 10 guests