summaryrefslogtreecommitdiff
path: root/Zend
diff options
context:
space:
mode:
authorDmitry Stogov <dmitry@zend.com>2021-03-01 13:43:22 +0300
committerDmitry Stogov <dmitry@zend.com>2021-03-01 13:43:22 +0300
commitb0c7ea4919e54b9507713543f49c9fd6246d44bf (patch)
tree6576f1cef77a371913fd01b217f1165e11f15d49 /Zend
parent47a2e5c785cdba71e003d9ad77cb799d4be88806 (diff)
parentc9a9362c78e866919630f1d78303848fba35bd0a (diff)
downloadphp-git-b0c7ea4919e54b9507713543f49c9fd6246d44bf.tar.gz
Change the order of properties used in foreach(), var_dump(), serialize(), comparison, etc. Now properties are ordered according to their layout in zend_object structure.
Diffstat (limited to 'Zend')
-rw-r--r--Zend/tests/bug27798.phpt4
-rw-r--r--Zend/tests/bug60536_003.phpt8
-rw-r--r--Zend/tests/bug79862.phpt8
-rw-r--r--Zend/tests/get_mangled_object_vars.phpt2
-rw-r--r--Zend/tests/objects_033.phpt4
-rw-r--r--Zend/tests/traits/property008.phpt12
-rw-r--r--Zend/zend_object_handlers.c54
7 files changed, 40 insertions, 52 deletions
diff --git a/Zend/tests/bug27798.phpt b/Zend/tests/bug27798.phpt
index 310fd97991..c16c5c825d 100644
--- a/Zend/tests/bug27798.phpt
+++ b/Zend/tests/bug27798.phpt
@@ -57,12 +57,12 @@ array(3) {
}
Child::__construct
array(3) {
- ["Baz"]=>
- int(4)
["Foo"]=>
int(1)
["Bar"]=>
int(2)
+ ["Baz"]=>
+ int(4)
}
array(1) {
["Foo"]=>
diff --git a/Zend/tests/bug60536_003.phpt b/Zend/tests/bug60536_003.phpt
index 3ba23b9288..8696591bb2 100644
--- a/Zend/tests/bug60536_003.phpt
+++ b/Zend/tests/bug60536_003.phpt
@@ -32,14 +32,14 @@ var_dump($b);
?>
--EXPECTF--
object(SubclassA)#%d (2) {
- ["hello":"SubclassA":private]=>
- int(0)
["hello":"BaseWithPropA":private]=>
int(0)
+ ["hello":"SubclassA":private]=>
+ int(0)
}
object(SubclassB)#%d (2) {
- ["hello":"SubclassB":private]=>
- int(0)
["hello":"BaseWithTPropB":private]=>
int(0)
+ ["hello":"SubclassB":private]=>
+ int(0)
}
diff --git a/Zend/tests/bug79862.phpt b/Zend/tests/bug79862.phpt
index b923da78b4..a04dc5c9ac 100644
--- a/Zend/tests/bug79862.phpt
+++ b/Zend/tests/bug79862.phpt
@@ -45,14 +45,14 @@ NULL
NULL
NULL
object(c)#1 (6) {
- ["prop1"]=>
- int(1)
- ["prop2":protected]=>
- int(2)
["prop3":"a":private]=>
int(3)
["prop4":"a":private]=>
int(4)
+ ["prop1"]=>
+ int(1)
+ ["prop2":protected]=>
+ int(2)
["prop5"]=>
int(5)
["prop6"]=>
diff --git a/Zend/tests/get_mangled_object_vars.phpt b/Zend/tests/get_mangled_object_vars.phpt
index 735548579e..f9ad008a33 100644
--- a/Zend/tests/get_mangled_object_vars.phpt
+++ b/Zend/tests/get_mangled_object_vars.phpt
@@ -33,10 +33,10 @@ echo "\n";
?>
--EXPECT--
array (
- '' . "\0" . 'B' . "\0" . 'priv' => 4,
'pub' => 1,
'' . "\0" . '*' . "\0" . 'prot' => 2,
'' . "\0" . 'A' . "\0" . 'priv' => 3,
+ '' . "\0" . 'B' . "\0" . 'priv' => 4,
'dyn' => 5,
6 => 6,
)
diff --git a/Zend/tests/objects_033.phpt b/Zend/tests/objects_033.phpt
index 3c19864490..edb722b040 100644
--- a/Zend/tests/objects_033.phpt
+++ b/Zend/tests/objects_033.phpt
@@ -24,5 +24,5 @@ print_r($a, true);
var_dump($a < $b);
?>
--EXPECT--
-bool(false)
-bool(false)
+bool(true)
+bool(true)
diff --git a/Zend/tests/traits/property008.phpt b/Zend/tests/traits/property008.phpt
index ff265be2a0..d4d57f379a 100644
--- a/Zend/tests/traits/property008.phpt
+++ b/Zend/tests/traits/property008.phpt
@@ -42,20 +42,20 @@ var_dump($b);
?>
--EXPECT--
object(SubclassClassicInheritance)#1 (2) {
- ["hello":"SubclassClassicInheritance":private]=>
- int(0)
["hello":"BaseWithPropA":private]=>
int(0)
+ ["hello":"SubclassClassicInheritance":private]=>
+ int(0)
}
object(SubclassA)#2 (2) {
- ["hello":"SubclassA":private]=>
- int(0)
["hello":"BaseWithPropA":private]=>
int(0)
+ ["hello":"SubclassA":private]=>
+ int(0)
}
object(SubclassB)#3 (2) {
- ["hello":"SubclassB":private]=>
- int(0)
["hello":"BaseWithTPropB":private]=>
int(0)
+ ["hello":"SubclassB":private]=>
+ int(0)
}
diff --git a/Zend/zend_object_handlers.c b/Zend/zend_object_handlers.c
index b903afb8ba..94d2ff8cf4 100644
--- a/Zend/zend_object_handlers.c
+++ b/Zend/zend_object_handlers.c
@@ -63,41 +63,24 @@ ZEND_API void rebuild_object_properties(zend_object *zobj) /* {{{ */
if (!zobj->properties) {
zend_property_info *prop_info;
zend_class_entry *ce = zobj->ce;
- uint32_t flags = 0;
+ int i;
zobj->properties = zend_new_array(ce->default_properties_count);
if (ce->default_properties_count) {
zend_hash_real_init_mixed(zobj->properties);
- ZEND_HASH_FOREACH_PTR(&ce->properties_info, prop_info) {
- if (!(prop_info->flags & ZEND_ACC_STATIC)) {
- flags |= prop_info->flags;
+ for (i = 0; i < ce->default_properties_count; i++) {
+ prop_info = ce->properties_info_table[i];
- if (UNEXPECTED(Z_TYPE_P(OBJ_PROP(zobj, prop_info->offset)) == IS_UNDEF)) {
- HT_FLAGS(zobj->properties) |= HASH_FLAG_HAS_EMPTY_IND;
- }
-
- _zend_hash_append_ind(zobj->properties, prop_info->name,
- OBJ_PROP(zobj, prop_info->offset));
+ if (!prop_info) {
+ continue;
}
- } ZEND_HASH_FOREACH_END();
- if (flags & ZEND_ACC_CHANGED) {
- while (ce->parent && ce->parent->default_properties_count) {
- ce = ce->parent;
- ZEND_HASH_FOREACH_PTR(&ce->properties_info, prop_info) {
- if (prop_info->ce == ce &&
- !(prop_info->flags & ZEND_ACC_STATIC) &&
- (prop_info->flags & ZEND_ACC_PRIVATE)) {
- zval zv;
-
- if (UNEXPECTED(Z_TYPE_P(OBJ_PROP(zobj, prop_info->offset)) == IS_UNDEF)) {
- HT_FLAGS(zobj->properties) |= HASH_FLAG_HAS_EMPTY_IND;
- }
-
- ZVAL_INDIRECT(&zv, OBJ_PROP(zobj, prop_info->offset));
- zend_hash_add(zobj->properties, prop_info->name, &zv);
- }
- } ZEND_HASH_FOREACH_END();
+
+ if (UNEXPECTED(Z_TYPE_P(OBJ_PROP(zobj, prop_info->offset)) == IS_UNDEF)) {
+ HT_FLAGS(zobj->properties) |= HASH_FLAG_HAS_EMPTY_IND;
}
+
+ _zend_hash_append_ind(zobj->properties, prop_info->name,
+ OBJ_PROP(zobj, prop_info->offset));
}
}
}
@@ -1555,6 +1538,7 @@ ZEND_API int zend_std_compare_objects(zval *o1, zval *o2) /* {{{ */
}
if (!zobj1->properties && !zobj2->properties) {
zend_property_info *info;
+ int i;
if (!zobj1->ce->default_properties_count) {
return 0;
@@ -1570,14 +1554,18 @@ ZEND_API int zend_std_compare_objects(zval *o1, zval *o2) /* {{{ */
}
Z_PROTECT_RECURSION_P(o1);
- ZEND_HASH_FOREACH_PTR(&zobj1->ce->properties_info, info) {
- zval *p1 = OBJ_PROP(zobj1, info->offset);
- zval *p2 = OBJ_PROP(zobj2, info->offset);
+ for (i = 0; i < zobj1->ce->default_properties_count; i++) {
+ zval *p1, *p2;
+
+ info = zobj1->ce->properties_info_table[i];
- if (info->flags & ZEND_ACC_STATIC) {
+ if (!info) {
continue;
}
+ p1 = OBJ_PROP(zobj1, info->offset);
+ p2 = OBJ_PROP(zobj2, info->offset);
+
if (Z_TYPE_P(p1) != IS_UNDEF) {
if (Z_TYPE_P(p2) != IS_UNDEF) {
int ret;
@@ -1597,7 +1585,7 @@ ZEND_API int zend_std_compare_objects(zval *o1, zval *o2) /* {{{ */
return 1;
}
}
- } ZEND_HASH_FOREACH_END();
+ }
Z_UNPROTECT_RECURSION_P(o1);
return 0;