[patch] Zend/zend_compile.c - bug #29446 (PHP 5 allows class constants to be overriden)

From: Date: Fri, 10 Sep 2004 05:57:23 +0000
Subject: [patch] Zend/zend_compile.c - bug #29446 (PHP 5 allows class constants to be overriden)
Groups: php.internals 
Request: Send a blank email to internals+get-12696@lists.php.net to get a copy of this message
Yet another patch for ZE. This one fixes rather strange problem - ZE allows multiple declarations of the same class constant. It could be a minor BC break, but I'm sure it's a bug. -- Wbr, Antony Dovgal aka tony2001 tony2001@phpclub.net || antony@dovgal.com

Index: zend_compile.c =================================================================== RCS file: /repository/ZendEngine2/zend_compile.c,v retrieving revision 1.586 diff -u -r1.586 zend_compile.c --- zend_compile.c 2 Sep 2004 17:27:44 -0000 1.586 +++ zend_compile.c 6 Sep 2004 05:28:45 -0000 @@ -2652,7 +2652,7 @@ void zend_do_declare_class_constant(znode *var_name, znode *value TSRMLS_DC) { zval *property; - + if(Z_TYPE(value->u.constant) == IS_CONSTANT_ARRAY) { zend_error(E_COMPILE_ERROR, "Arrays are not allowed in class constants"); } @@ -2666,8 +2666,10 @@ property->type = IS_NULL; } - zend_hash_update(&CG(active_class_entry)->constants_table, var_name->u.constant.value.str.val, var_name->u.constant.value.str.len+1, &property, sizeof(zval *), NULL); - + if (zend_hash_add(&CG(active_class_entry)->constants_table, var_name->u.constant.value.str.val, var_name->u.constant.value.str.len+1, &property, sizeof(zval *), NULL)==FAILURE) { + FREE_ZVAL(property); + zend_error(E_COMPILE_ERROR, "Cannot redefine class constant %s::%s", CG(active_class_entry)->name, var_name->u.constant.value.str.val); + } FREE_PNODE(var_name); }
« previous php.internals (#12696) next »