I would like to "unload" a class loaded previously by require_once.
Mainly I am working on a daemon where handler-classes should be loaded and
unloaded on demand.
I did not find a way to drop a class from memory and reload it again from a
(maybe changed) file. There are some work-a-rounds on the net like using
eval or create_function. But is there any clean way to drop a class ?
Carsten
Hi,
Carsten Harnisch wrote:
I would like to "unload" a class loaded previously by require_once.
Mainly I am working on a daemon where handler-classes should be loaded and
unloaded on demand.
You could remove a class using classkit ...
http://pecl.php.net/package/classkit
johannes
Johannes Schlueter wrote:
I would like to "unload" a class loaded previously by require_once.
Mainly I am working on a daemon where handler-classes should be loaded and
unloaded on demand.You could remove a class using classkit ...
No, you could remove the methods that belong to the class and/or rename
the class, but class removal isn't possible. (What would happen to the
instanciated objects?)
S
Sean Coates wrote:
What would happen to the instanciated objects?
Only allowing class unloading for classes that have no instantiated
objects would be an option.
--
Sebastian Bergmann http://www.sebastian-bergmann.de/
GnuPG Key: 0xB85B5D69 / 27A7 2B14 09E4 98CD 6277 0E5B 6867 C514 B85B 5D69
What would happen to the instanciated objects?
Only allowing class unloading for classes that have no instantiated
objects would be an option.
And how would you know if it'd been instantiated? Even if you recursively
looped through every variable hash from EG(symbol_table) on down, there'd
still be the possibility that one or two objects would be hiding in a
resource somewhere (i.e. php_stream_context).
This is also why delete() doesn't (and likely won't ever) exist in PHP.
Anyway, sounds like what he wants is classkit_import().
-Sara
Sara Golemon wrote:
What would happen to the instanciated objects?
Only allowing class unloading for classes that have no instantiated
objects would be an option.And how would you know if it'd been instantiated? Even if you recursively
looped through every variable hash from EG(symbol_table) on down, there'd
still be the possibility that one or two objects would be hiding in a
resource somewhere (i.e. php_stream_context).
Is there a technical limitation to loop through every internal hash
which could possible hold an instantiated object?
If there would exist functions like
- class_has_instanciated_objects()
- class_get_instanciated_objects()
I guess noone would expect them to be quick or fast.
Of course there's the fact to respect the class hierarchy which adds
complexity.
I can imagine that optimizers and such would have problems with it. But
albeit, technically?
- Markus
Sara Golemon wrote:
What would happen to the instanciated objects?
Only allowing class unloading for classes that have no instantiated
objects would be an option.And how would you know if it'd been instantiated? Even if you
recursively looped through every variable hash from EG(symbol_table)
on down, there'd still be the possibility that one or two objects
would be hiding in a resource somewhere (i.e. php_stream_context).Is there a technical limitation to loop through every internal hash
which could possible hold an instantiated object?
Yes. There are obscure, arbitrary places these things can live.
George