Skip to content

Commit ce95a68

Browse files
committed
Make readonly props fallback to read_property in get_property_ptr_ptr
read_property will then fail for accessing an uninitialized property.
1 parent 3a1eccb commit ce95a68

File tree

4 files changed

+9
-7
lines changed

4 files changed

+9
-7
lines changed

Zend/tests/readonly_props/array_append_initialization.phpt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,5 +33,5 @@ try {
3333

3434
?>
3535
--EXPECT--
36-
Cannot modify readonly property C::$a
36+
Typed property C::$a must not be accessed before initialization
3737
Cannot initialize readonly property C::$a from global scope

Zend/tests/readonly_props/gh7942.phpt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,4 +19,4 @@ try {
1919

2020
?>
2121
--EXPECT--
22-
Cannot modify readonly property Foo::$bar
22+
Typed property Foo::$bar must not be accessed before initialization

Zend/zend_object_handlers.c

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1021,10 +1021,12 @@ ZEND_API zval *zend_std_get_property_ptr_ptr(zend_object *zobj, zend_string *nam
10211021
zend_error(E_WARNING, "Undefined property: %s::$%s", ZSTR_VAL(zobj->ce->name), ZSTR_VAL(name));
10221022
}
10231023
} else if (prop_info && UNEXPECTED(prop_info->flags & ZEND_ACC_READONLY)) {
1024-
if (verify_readonly_initialization_access(prop_info, zobj->ce, name, "initialize")) {
1025-
zend_readonly_property_modification_error(prop_info);
1024+
if (!verify_readonly_initialization_access(prop_info, zobj->ce, name, "initialize")) {
1025+
retval = &EG(error_zval);
1026+
} else {
1027+
/* Readonly property, delegate to read_property + write_property. */
1028+
retval = NULL;
10261029
}
1027-
retval = &EG(error_zval);
10281030
}
10291031
} else {
10301032
/* we do have getter - fail and let it try again with usual get/set */

ext/opcache/tests/jit/fetch_obj_006.phpt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,8 @@ $appendProp2 = (function() {
2323
$appendProp2();
2424
?>
2525
--EXPECTF--
26-
Fatal error: Uncaught Error: Cannot modify readonly property Test::$prop in %sfetch_obj_006.php:13
26+
Fatal error: Uncaught Error: Typed property Test::$prop must not be accessed before initialization in %sfetch_obj_006.php:13
2727
Stack trace:
2828
#0 %sfetch_obj_006.php(15): Test->{closure}()
2929
#1 {main}
30-
thrown in %sfetch_obj_006.php on line 13
30+
thrown in %sfetch_obj_006.php on line 13

0 commit comments

Comments
 (0)