-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Hello Internals,

Has anyone given thought to a feature that allows (PHP) developer to
invalidate classes (allowing the developer to re-load the class, with
modified code)? I realize that this is not possible now, and for good
reason. But I think the idea has potential.

I asked Sara about this, yesterday, after the idea occurred to me, and
she graciously whipped up a small extension that does exactly what I'm
looking for, but she told me she thought it was a bad idea to be doing
this (and also allows destruction of functions). I agree: without the
proper safety nets, this is a dangerous thing to be doing.

So, why do I want this functionality, in the first place? Consider a
long-running application (not a web page, but, for instance, a
sockets-based application). It would be very useful for me, as a
developer, to be able to re-load parts of the application, without
tossing the whole current instance of PHP (and all associated resources)
- -- ie, doesn't release socket connections, but allows re-loading of the
associated handlers. This could be accomplished by invalidating a class
(destroying it, and marking all instanciated objects with a special type
(__PHP_Destroyed_Class comes to mind, after __PHP_Incomplete_Class), and
re-declaring the class.

- -- sample code (working) --
<?php
eval('Class Foo { function name() {  echo "Foo\n";  } }');
Foo::name();
shiva_destroy_class('Foo');
eval('Class Foo { function name() {  echo "Bar\n";  } }');
Foo::name();
?>
- -- output --
Foo
Bar

I also spoke (typed) with Stig, who told me that this sounds more like a
PHP 6 feature. I understand that class destruction breaks a lot of
assumptions. As Sara pointed out, it will definitely break optimizers.
Also, the potential for segfault is very high:
Class Foo { function name() {  echo "Foo\n";  } }; $Foo = new Foo();
shiva_destroy_class('Foo'); eval('Class Foo { function name() {  echo
"Bar\n";  } };'); $Foo->name();   results in segfault..

I'm, admittedly, completely out of my league here.. I played with the
API a little, and was reminded of this. (-:

It may seem like a stupid idea at first, but I think there's some value
in re-loading pieces of code, and with the proper object
counting/invalidation, sounds like it could be safe, but like I said, I
don't know what I'm doing.

Is this worth further discussion?

S
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.4 (GNU/Linux)
Comment: Using GnuPG with Thunderbird - http://enigmail.mozdev.org

iD8DBQFBI9G1WppknrQMxQIRAjPOAJ9gsQ6AZlwd5QI6+CYerGOgtsKwhQCfejxZ
zfMP6MgKuGvHx7dO4mPNh90=
=GR/W
-----END PGP SIGNATURE-----

--
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: http://www.php.net/unsub.php



Reply via email to