Skip to content

Commit 13fd5e0

Browse files
committed
Fixed bug #78226
1 parent f945c82 commit 13fd5e0

File tree

4 files changed

+45
-18
lines changed

4 files changed

+45
-18
lines changed

Zend/tests/bug63462.phpt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,5 @@ __isset publicProperty
6767
__isset protectedProperty
6868
__isset privateProperty
6969
__set nonExisting
70-
__set publicProperty
7170
__set protectedProperty
7271
__set privateProperty

Zend/tests/bug78226.phpt

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
--TEST--
2+
Bug #78226: Unexpected __set behavior with typed properties
3+
--FILE--
4+
<?php
5+
6+
class Test {
7+
public int $prop1;
8+
public $prop2;
9+
10+
public function __set($name, $val) {
11+
echo "__set($name, $val)\n";
12+
}
13+
}
14+
15+
$test = new Test;
16+
unset($test->prop2);
17+
18+
$test->prop1 = 1;
19+
$test->prop2 = 2;
20+
21+
var_dump($test);
22+
23+
?>
24+
--EXPECT--
25+
object(Test)#1 (2) {
26+
["prop1"]=>
27+
int(1)
28+
["prop2"]=>
29+
int(2)
30+
}

Zend/zend_object_handlers.c

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -819,23 +819,21 @@ ZEND_API zval *zend_std_write_property(zval *object, zval *member, zval *value,
819819

820820
if (EXPECTED(IS_VALID_PROPERTY_OFFSET(property_offset))) {
821821
variable_ptr = OBJ_PROP(zobj, property_offset);
822-
if (Z_TYPE_P(variable_ptr) != IS_UNDEF) {
823-
Z_TRY_ADDREF_P(value);
822+
Z_TRY_ADDREF_P(value);
824823

825-
if (UNEXPECTED(prop_info)) {
826-
ZVAL_COPY_VALUE(&tmp, value);
827-
if (UNEXPECTED(!zend_verify_property_type(prop_info, &tmp, EG(current_execute_data) && ZEND_CALL_USES_STRICT_TYPES(EG(current_execute_data))))) {
828-
Z_TRY_DELREF_P(value);
829-
variable_ptr = &EG(error_zval);
830-
goto exit;
831-
}
832-
value = &tmp;
824+
if (UNEXPECTED(prop_info)) {
825+
ZVAL_COPY_VALUE(&tmp, value);
826+
if (UNEXPECTED(!zend_verify_property_type(prop_info, &tmp, EG(current_execute_data) && ZEND_CALL_USES_STRICT_TYPES(EG(current_execute_data))))) {
827+
Z_TRY_DELREF_P(value);
828+
variable_ptr = &EG(error_zval);
829+
goto exit;
833830
}
831+
value = &tmp;
832+
}
834833

835834
found:
836-
zend_assign_to_variable(variable_ptr, value, IS_TMP_VAR, EG(current_execute_data) && ZEND_CALL_USES_STRICT_TYPES(EG(current_execute_data)));
837-
goto exit;
838-
}
835+
zend_assign_to_variable(variable_ptr, value, IS_TMP_VAR, EG(current_execute_data) && ZEND_CALL_USES_STRICT_TYPES(EG(current_execute_data)));
836+
goto exit;
839837
} else if (EXPECTED(IS_DYNAMIC_PROPERTY_OFFSET(property_offset))) {
840838
if (EXPECTED(zobj->properties != NULL)) {
841839
if (UNEXPECTED(GC_REFCOUNT(zobj->properties) > 1)) {

tests/classes/unset_properties.phpt

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -132,22 +132,22 @@ true
132132
__isset "publicProperty"
133133
__get "publicProperty"
134134
__get "publicProperty"
135-
__set "publicProperty" to "new publicProperty value via setter"
135+
136136
new publicProperty value via setter
137-
__set "publicProperty" to "new publicProperty value via public access"
137+
138138
true
139139
new publicProperty value via public access
140140

141141
protectedProperty set
142142
__isset "protectedProperty"false
143143
__get "protectedProperty"
144-
__set "protectedProperty" to "new protectedProperty value via setter"
144+
145145
__isset "protectedProperty"true
146146
new protectedProperty value via setter
147147

148148
privateProperty set
149149
__isset "privateProperty"false
150150
__get "privateProperty"
151-
__set "privateProperty" to "new privateProperty value via setter"
151+
152152
__isset "privateProperty"true
153153
new privateProperty value via setter

0 commit comments

Comments
 (0)