Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:12245 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 39077 invoked by uid 1010); 19 Aug 2004 05:05:54 -0000 Delivered-To: ezmlm-scan-internals@lists.php.net Delivered-To: ezmlm-internals@lists.php.net Received: (qmail 38984 invoked from network); 19 Aug 2004 05:05:54 -0000 Received: from unknown (HELO smtp.unet.ru) (213.219.244.56) by pb1.pair.com with SMTP; 19 Aug 2004 05:05:54 -0000 Received: from host.phpclub.net by smtp.unet.ru (8.12.9/Unet) with ESMTP id i7J55re7037365 for ; Thu, 19 Aug 2004 09:05:53 +0400 (MSD) Received: from s17.hibet.ru by host.phpclub.net (8.12.6/Unet) with ESMTP id i7J55r3w046042 for ; Thu, 19 Aug 2004 09:05:53 +0400 (MSD) Date: Thu, 19 Aug 2004 09:04:36 +0400 To: internals@lists.php.net Message-ID: <20040819090436.788cd2bf.tony2001@phpclub.net> In-Reply-To: <4123D1B5.3080203@caedmon.net> References: <4123D1B5.3080203@caedmon.net> X-Mailer: Sylpheed version 0.9.12 (GTK+ 1.2.10; i686-pc-linux-gnu) Mime-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Subject: Re: [PHP-DEV] Class Destruction / Reloading From: tony2001@phpclub.net (Antony Dovgal) On Wed, 18 Aug 2004 18:01:25 -0400 Sean Coates wrote: > -----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. > > - -- sample code (working) -- > 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 Well, some time ago I wrote a small functions, that does exactly the same: PHP_FUNCTION(unregister_class) { zval **class; zend_class_entry *ce = NULL, **pce; char *lowercase_name = NULL; if (ZEND_NUM_ARGS() != 1 || zend_get_parameters_ex(1, &class)==FAILURE) { ZEND_WRONG_PARAM_COUNT(); } convert_to_string_ex(class); if (zend_lookup_class(Z_STRVAL_PP(class), Z_STRLEN_PP(class), &pce TSRMLS_CC) == SUCCESS) { ce = *pce; } if (!ce) { RETURN_FALSE; } lowercase_name = emalloc(ce->name_length+1); zend_str_tolower_copy(lowercase_name, ce->name, ce->name_length); if (zend_hash_del(CG(class_table), lowercase_name, ce->name_length+1) == FAILURE) { efree(lowercase_name); RETURN_FALSE; } efree(lowercase_name); RETURN_TRUE; } Dunno if it's a good implementation, but the idea was to be able to reload classes in the looong running PHP application. However, I don't think it should be implemented in PHP ever, 'cos this (and many more) functionality is/should be implemented in SRM. -- Wbr, Antony Dovgal aka tony2001 tony2001@phpclub.net || antony@dovgal.com