Jump to content

Unloading a class


niche
 Share

Recommended Posts

Is it possible to rename a class? EDIT: I mean rename a class once it's loaded?

Edited by niche
Link to comment
Share on other sites

Why do you want to do that anyway? If the problem is in loading order, you can prepend a different autoload function that would load the correct class.

Link to comment
Share on other sites

I have a conflict in a vender supplied class. I need to use the same class in two different situations. One situation requires a different version of a class then the other situation requires. I've contacted the vender, but thought I'd investigate alternatives in the meantime. So far, I've discovered namespaces. I'm under the impression I can load the classes that are required in one situation, in one namespace and the others in a different namespace and access them separately. Is that consistent with how namespaces work?

Link to comment
Share on other sites

Not exactly... the two classes need to be defined in two different namespaces, at which point you can refer to either by a third namespace declaration at the top of the file where you use the class. Depending on that declaration (which is allocated per file, so if you need it conditionally, you'll have to conditionally include different "use" files), you can instantiate either or both classes from a single file.If you can open up the two versions, and add

namespace SomeNamespace1;

to the top of the first, and

namespace SomeNamespace2;

to the top of the second, then, in your code, you can have

use SomeNamespace1\ClassName as ClassName1;use SomeNamespace2\ClassName as ClassName2;//Further on...if (/*situation check*/) {$class = new ClassName1();} else {$class = new ClassName2();}//Use $class unconditionally

Link to comment
Share on other sites

Thanks justsomeguy and boen robot. I just noticed that I need v5.3. I'm using v5.2.9-2 so it will be a while before I can continue.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...