Re: Removing a declared class

From: Date: Fri, 15 Dec 2000 10:13:14 +0000
Subject: Re: Removing a declared class
References: 1 2  Groups: php.general 
Request: Send a blank email to php-general+get-30486@lists.php.net to get a copy of this message
Richard Lynch wrote: > > You can check if a class exists or not using... errr. I forget what it's > called. It's in the manual though. class_exists()? > > I don't think you can destroy a class though. > > It sounds like you have an include() problem more than a class problem. The problem was related to adaptors, ie. classes with the _same_ name, but which are implementing a uniform _interface_ to other different classes. The problem appeared when I included several such adaptors to benchmark their performance in a larger application. You are right that it was an include problem, after all, I just moved my includes about (ie. redesigned the included files) and the data export parts. Thus, now I have a benchmarking application for the classes. This is done for an article I hope to have finished for zez.org: about code before Christmas. Though the solution worked for my benchmarking, I can easily see examples of where this wouldn't be solvable by reordering includes. And that is where the problem appears. Use adaptors with care. People programming adaptors would also need to heed this problem, ie. I'm thinking things like database abstraction systems, etc. > For complex sites, I tend to start off include files like this: > > <?php > if (!is_defined('filenameinc')){ > define('filenameinc', 1); > #real code goes here... > } > ?> > > Replace filenameinc with the actual name of the file and extension or > whatever you like -- just make sure it's unique is the key. > > Now, it really doesn't matter how many times you include that file -- only > the first one is going to do anything. > > There is also a builtin include_once() function, but it may be undocumented > and/or only in recent versions... I did in fact use include_once() on each of the classes I included, but since the adaptors where named the same, I got a redeclaration of the adaptor class when I tried to adapt a second class. I'm contacting the author of the library to have him look into it, though for this exact application (templates) I can't forsee anyone (but me:) using different kinds of templates in their application. I think they would just settle for the type they like the most. But it has alerted me to the fact that making adaptors work isn't trivial, since if this had been a database adaptor, then I can easily forsee the need to use different databases on different RDBM systems. I hope this clarifies the problem I had. At least I'll get a couple of articles out of this:) -- Paul K Egell-Johnsen Developer/PR Manager zez.org: about code http://zez.org/

« previous php.general (#30486) next »