Topic: How does the extension system handle the same variable name

I am reading the code of the extension system, and a question pops-up, hope someone could help me out. smile

consider the following code

<?php
//hook place 1
//e.g. extension1 code will be place here
$myvar = 1;

/******some other php codes*************/

//hook place 2
//another extension using the same var name
$myvar = "that's bad";

/******some other php codes*************/

//hook place 3
//extension1 will use the $myvar
if ($myvar===1) //do something
?>

as you can see, it might create conflicts if there are vars using same name, i don't know if the 1.3 has already handled this, if yes, how? if no, hope we can avoid this problem then. Thanks. PunBB is really a fantastic application! I love it!

2 (edited by Vovochka 2008-04-29 10:20)

Re: How does the extension system handle the same variable name

No, such situation is not handled. I think you that if you want to use your own variables, you should give them unique names based on extension id.

UPD:
This is one of the hooks ideas. You can change values of some variables with your extension code. It's not kind of bug, it's feature. And of corse, mod writers should use these abilities carefully.

3 (edited by adama136 2008-04-30 01:52)

Re: How does the extension system handle the same variable name

If the hooks are written by not only one programmer and there are variables using the same name. What will happen? It will hard for us to find the bugs.:P

Re: How does the extension system handle the same variable name

As Vovochka said, if extension authors want to use variables for storage, they can create variables with their own names based on extension ID. There will be developer documentation at some point that explains more of these kinds of things. Essentially, there is no way to keep extension authors from stepping on each others toes deliberately. The method we use here for extensions is good in that it gives access to variables that you can't necessarily get otherwise (eg: a hook like what we have in a function lets you globalize a variable and use it: other systems would have to resort to using $_GLOBALS because of scope issues). On the other hand, it also means that your code is executed like regular code, which means it can overwrite variables unintentionally if you don't follow naming standards, etc. No different than a modification.
In the words of Spiderman: "With great power comes great responsibility." smile

http://fluxbb.org

Free PunBB Hosting - lots of mods, easy to customize

Re: How does the extension system handle the same variable name

yes, indeed, i was also thinking if it's possible to provide a feature to run punbb in safe-mode, just in case some extensions create serious problems that blocking normal access to the forum.

Re: How does the extension system handle the same variable name

Yes, there's a define in include/essentials.php that disables hooks that is commented out by default.

http://fluxbb.org

Free PunBB Hosting - lots of mods, easy to customize