[nycphp-talk] Eliminating namespace conflicts between scripts?
Brent Baisley
brenttech at gmail.com
Thu Aug 16 09:40:11 EDT 2007
Well, that's part of what classes are for, to manage namespaces. Since
you are probably not going to redo the open source app to use classes,
you'll have to minimize the name spaces your app uses. Although you
may just want to resolve conflicts as they come up.
You can put all your global variables into a single global variable
that can be an associative array. Then you are using only 1 global
name.
So this:
$var1 = 'xyz';
$var2 = 'abc';
becomes:
$myvars['var1'] = 'xyz';
$myvars['var2'] = 'abc';
You can put your functions into a class (or classes) and reference the
class "statically", so you just need to prefix your functions with the
class name. Statically referencing the function will give global scope
without having to declare global variables.
class MyFuncs {
function a {}
function b{}
...
}
To call function "a" you would change a() to MyFuncs::a();
Those are some ideas. Curl will add a lot of overhead, but I admit I
have gone that route before.
On 8/16/07, Cliff Hirsch <cliff at pinestream.com> wrote:
>
> I am tying a large open source ap into my main ap. This ap has numerous
> global variable and countless includes and classless functions. Thus, the
> chances for a namespace conflict with my primary application are high.
>
> Yet it needs to be tightly coupled with my ap. What do you suggest for
> achieving this? The safest approach might be to use curl, although it seems
> a bit silly to curl into your own project. And its probably slow, although I
> can cache the result so performance shouldn't be an issue.
>
> Thoughts?
>
> Cliff
>
> _______________________________________________
> New York PHP Community Talk Mailing List
> http://lists.nyphp.org/mailman/listinfo/talk
>
> NYPHPCon 2006 Presentations Online
> http://www.nyphpcon.com
>
> Show Your Participation in New York PHP
> http://www.nyphp.org/show_participation.php
>
More information about the talk
mailing list