Hello Zeev, hi Andi,

  atm it is not possible to unset static members of a class which is correct
since that would modify the class protocol. But it is possible to unset non
dynamic properties (defined in the class). This should also be prevented as
done with the attached patch.

I did it by checking whether the name is part of the default properties. This
works but maybe it is to slow. So perhaps it is a better solution to provide a
flag in the property_info but then we#d have to do that in every class
instantiation while my method would only take time when unset is used on
props.

Test code:
<?php
class u { var $x = 1; }
class t extends u {}
$o = new t;
$o->y=2;
$o->var_dump($o);
$o->unset($o->y);
$o->var_dump($o);
$o->unset($o->x);
$o->var_dump($o);'
?>

Result:
object(t)#1 (2) {
  ["x"]=>
  int(1)
  ["y"]=>
  int(2)
}
object(t)#1 (0) {
}


With Patch:
object(t)#1 (2) {
  ["x"]=>
  int(1)
  ["y"]=>
  int(2)
}
object(t)#1 (1) {
  ["x"]=>
  int(1)
}


Comments ?
  
Best regards,
 Marcus                          mailto:[EMAIL PROTECTED]
Index: Zend/zend_object_handlers.c
===================================================================
RCS file: /repository/ZendEngine2/zend_object_handlers.c,v
retrieving revision 1.55
diff -u -p -r1.55 zend_object_handlers.c
--- Zend/zend_object_handlers.c 1 Jul 2003 19:13:50 -0000       1.55
+++ Zend/zend_object_handlers.c 5 Jul 2003 14:05:13 -0000
@@ -383,6 +383,7 @@ static void zend_std_unset_property(zval
        zend_object *zobj;
        zval tmp_member;
        zend_property_info *property_info;
+       zval **pProp;
        
        zobj = Z_OBJ_P(object);
 
@@ -394,7 +395,11 @@ static void zend_std_unset_property(zval
        }
 
        property_info = zend_get_property_info(zobj, member TSRMLS_CC);
-       
+
+       if (zend_hash_find(&zobj->ce->default_properties, property_info->name, 
property_info->name_length+1, (void **) &pProp) == SUCCESS) {
+               zend_error(E_ERROR, "Attempt to unset non dynamic property %s::$%s", 
zobj->ce->name, property_info->name);
+       }
+               
        zend_hash_del(zobj->properties, property_info->name, 
property_info->name_length+1);
        if (member == &tmp_member) {
                zval_dtor(member);
-- 
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to