[RFC] Improve embedding through prefixing names

Note: We are moving the topics of this forum and it will be deleted at some point

Publish your own request for comments/change or patches for the next version of phpBB. Discuss the contributions and proposals of others. Upcoming releases are 3.2/Rhea and 3.3.
Post Reply
User avatar
naderman
Consultant
Posts: 1727
Joined: Sun Jan 11, 2004 2:11 am
Location: Berlin, Germany
Contact:

[RFC] Improve embedding through prefixing names

Post by naderman »

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?

User avatar
imkingdavid
Registered User
Posts: 1050
Joined: Thu Jul 30, 2009 12:06 pm

Re: [RFC] Improve embedding through prefixing names

Post by imkingdavid »

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
MichaelC
Development Team
Development Team
Posts: 889
Joined: Thu Jan 28, 2010 6:29 pm

Re: [RFC] Improve embedding through prefixing names

Post by MichaelC »

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
Formerly known as 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
imkingdavid
Registered User
Posts: 1050
Joined: Thu Jul 30, 2009 12:06 pm

Re: [RFC] Improve embedding through prefixing names

Post by imkingdavid »

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
MichaelC
Development Team
Development Team
Posts: 889
Joined: Thu Jan 28, 2010 6:29 pm

Re: [RFC] Improve embedding through prefixing names

Post by MichaelC »

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?
Formerly known as 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
brunoais
Registered User
Posts: 964
Joined: Fri Dec 18, 2009 3:55 pm

Re: [RFC] Improve embedding through prefixing names

Post by brunoais »

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.

User avatar
callumacrae
Former Team Member
Posts: 1046
Joined: Tue Apr 27, 2010 9:37 am
Location: England
Contact:

Re: [RFC] Improve embedding through prefixing names

Post by callumacrae »

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
Made by developers, for developers!
My blog

User avatar
imkingdavid
Registered User
Posts: 1050
Joined: Thu Jul 30, 2009 12:06 pm

Re: [RFC] Improve embedding through prefixing names

Post by imkingdavid »

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
MichaelC
Development Team
Development Team
Posts: 889
Joined: Thu Jan 28, 2010 6:29 pm

Re: [RFC] Improve embedding through prefixing names

Post by MichaelC »

So all or some of the functions?
Formerly known as 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.

Post Reply