Skip to content

Commit 2bb126b

Browse files
committed
Don't allow readonly -> readwrite change during inheritance
1 parent af61092 commit 2bb126b

File tree

2 files changed

+7
-6
lines changed

2 files changed

+7
-6
lines changed
Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
--TEST--
2-
Can replace readonly with readwrite
2+
Cannot replace readonly with readwrite
33
--FILE--
44
<?php
55

@@ -11,6 +11,5 @@ class B extends A {
1111
}
1212

1313
?>
14-
===DONE===
15-
--EXPECT--
16-
===DONE===
14+
--EXPECTF--
15+
Fatal error: Cannot redeclare readonly property A::$prop as non-readonly B::$prop in %s on line %d

Zend/zend_inheritance.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1245,10 +1245,12 @@ static void do_inherit_property(zend_property_info *parent_info, zend_string *ke
12451245
(parent_info->flags & ZEND_ACC_STATIC) ? "static " : "non static ", ZSTR_VAL(parent_info->ce->name), ZSTR_VAL(key),
12461246
(child_info->flags & ZEND_ACC_STATIC) ? "static " : "non static ", ZSTR_VAL(ce->name), ZSTR_VAL(key));
12471247
}
1248-
if (UNEXPECTED((child_info->flags & ZEND_ACC_READONLY) && !(parent_info->flags & ZEND_ACC_READONLY))) {
1248+
if (UNEXPECTED((child_info->flags & ZEND_ACC_READONLY) != (parent_info->flags & ZEND_ACC_READONLY))) {
12491249
zend_error_noreturn(E_COMPILE_ERROR,
1250-
"Cannot redeclare non-readonly property %s::$%s as readonly %s::$%s",
1250+
"Cannot redeclare %s property %s::$%s as %s %s::$%s",
1251+
parent_info->flags & ZEND_ACC_READONLY ? "readonly" : "non-readonly",
12511252
ZSTR_VAL(parent_info->ce->name), ZSTR_VAL(key),
1253+
child_info->flags & ZEND_ACC_READONLY ? "readonly" : "non-readonly",
12521254
ZSTR_VAL(ce->name), ZSTR_VAL(key));
12531255
}
12541256

0 commit comments

Comments
 (0)