cvs: ZendEngine2 / zend_builtin_functions.c
| From: | Marcus Boerger | Date: | Tue, 12 Oct 2004 22:19:44 +0000 |
| Subject: | cvs: ZendEngine2 / zend_builtin_functions.c | ||
| Groups: | php.zend-engine.cvs | ||
| Request: | Send a blank email to php-zend-engine-cvs+get-3094@lists.php.net to get a copy of this message | ||
helly Tue Oct 12 18:19:44 2004 EDT
Modified files:
/ZendEngine2 zend_builtin_functions.c
Log:
Bug #30381 Strange results with get_class_vars()
http://cvs.php.net/diff.php/ZendEngine2/zend_builtin_functions.c?r1=1.251&r2=1.252&ty=u
Index: ZendEngine2/zend_builtin_functions.c
diff -u ZendEngine2/zend_builtin_functions.c:1.251 ZendEngine2/zend_builtin_functions.c:1.252
--- ZendEngine2/zend_builtin_functions.c:1.251 Tue Oct 12 07:01:08 2004
+++ ZendEngine2/zend_builtin_functions.c Tue Oct 12 18:19:43 2004
@@ -17,7 +17,7 @@
+----------------------------------------------------------------------+
*/
-/* $Id: zend_builtin_functions.c,v 1.251 2004/10/12 11:01:08 helly Exp $ */
+/* $Id: zend_builtin_functions.c,v 1.252 2004/10/12 22:19:43 helly Exp $ */
#include "zend.h"
#include "zend_API.h"
@@ -657,68 +657,72 @@
/* }}} */
+/* {{{ add_class_vars */
+static void add_class_vars(zend_class_entry *ce, HashTable *properties, zval *return_value
TSRMLS_DC)
+{
+ int instanceof = EG(scope) && instanceof_function(EG(scope), ce TSRMLS_CC);
+
+ if (zend_hash_num_elements(properties) > 0) {
+ HashPosition pos;
+ zval **prop;
+
+ zend_hash_internal_pointer_reset_ex(properties, &pos);
+ while (zend_hash_get_current_data_ex(properties, (void **) &prop, &pos) == SUCCESS) {
+ char *key, *class_name, *prop_name;
+ uint key_len;
+ ulong num_index;
+ zval *prop_copy;
+
+ zend_hash_get_current_key_ex(properties, &key, &key_len, &num_index, 0, &pos);
+ zend_hash_move_forward_ex(properties, &pos);
+ zend_unmangle_property_name(key, &class_name, &prop_name);
+ if (class_name) {
+ if (class_name[0] != '*' && strcmp(class_name, ce->name)) {
+ /* filter privates from base classes */
+ continue;
+ } else if (!instanceof) {
+ /* filter protected if not inside class */
+ continue;
+ }
+ }
+
+ /* copy: enforce read only access */
+ ALLOC_ZVAL(prop_copy);
+ *prop_copy = **prop;
+ zval_copy_ctor(prop_copy);
+ INIT_PZVAL(prop_copy);
+
+ /* this is necessary to make it able to work with default array
+ * properties, returned to user */
+ if (Z_TYPE_P(prop_copy) == IS_CONSTANT_ARRAY || Z_TYPE_P(prop_copy) == IS_CONSTANT) {
+ zval_update_constant(&prop_copy, 0 TSRMLS_CC);
+ }
+
+ add_assoc_zval(return_value, prop_name, prop_copy);
+ }
+ }
+}
+/* }}} */
+
+
/* {{{ proto array get_class_vars(string class_name)
- Returns an array of default properties of the class */
+ Returns an array of default properties of the class. */
ZEND_FUNCTION(get_class_vars)
{
- zval **class_name;
- zend_class_entry *ce, **pce;
- int instanceof;
+ char *class_name;
+ int class_name_len;
+ zend_class_entry **pce;
- if (ZEND_NUM_ARGS() != 1 || zend_get_parameters_ex(1, &class_name)==FAILURE) {
- ZEND_WRONG_PARAM_COUNT();
+ if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &class_name,
&class_name_len) == FAILURE) {
+ return;
}
- convert_to_string_ex(class_name);
-
- if (zend_lookup_class(Z_STRVAL_PP(class_name), Z_STRLEN_PP(class_name), &pce TSRMLS_CC) ==
FAILURE) {
+ if (zend_lookup_class(class_name, class_name_len, &pce TSRMLS_CC) == FAILURE) {
RETURN_FALSE;
} else {
- ce = *pce;
-
- instanceof = EG(scope) && instanceof_function(EG(scope), ce TSRMLS_CC);
-
array_init(return_value);
-
- if (zend_hash_num_elements(&ce->default_properties) > 0) {
- HashPosition pos;
- zval **prop;
-
- zend_hash_internal_pointer_reset_ex(&ce->default_properties, &pos);
- while (zend_hash_get_current_data_ex(&ce->default_properties, (void **) &prop,
&pos) == SUCCESS) {
- char *key, *class_name, *prop_name;
- uint key_len;
- ulong num_index;
- zval *prop_copy;
-
- zend_hash_get_current_key_ex(&ce->default_properties, &key, &key_len,
&num_index, 0, &pos);
- zend_hash_move_forward_ex(&ce->default_properties, &pos);
- zend_unmangle_property_name(key, &class_name, &prop_name);
- if (class_name) {
- if (class_name[0] != '*' && strcmp(class_name, ce->name)) {
- /* filter privates from base classes */
- continue;
- } else if (!instanceof) {
- /* filter protected if not inside class */
- continue;
- }
- }
-
- /* copy: enforce read only access */
- ALLOC_ZVAL(prop_copy);
- *prop_copy = **prop;
- zval_copy_ctor(prop_copy);
- INIT_PZVAL(prop_copy);
-
- /* this is necessary to make it able to work with default array
- * properties, returned to user */
- if (Z_TYPE_P(prop_copy) == IS_CONSTANT_ARRAY || Z_TYPE_P(prop_copy) == IS_CONSTANT) {
- zval_update_constant(&prop_copy, 0 TSRMLS_CC);
- }
-
- add_assoc_zval(return_value, prop_name, prop_copy);
- }
- }
+ add_class_vars(*pce, &(*pce)->default_properties, return_value TSRMLS_CC);
+ add_class_vars(*pce, (*pce)->static_members, return_value TSRMLS_CC);
}
}
/* }}} */