On Wed, 18 Aug 2004 18:01:25 -0400
Sean Coates <[EMAIL PROTECTED]> 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.
> 
<skip>
> - -- 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


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
[EMAIL PROTECTED] || [EMAIL PROTECTED]

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

Reply via email to