Skip to content

Commit 92d70bc

Browse files
committed
refactor: improved misleading error handling
1 parent b4df02d commit 92d70bc

File tree

5 files changed

+16
-7
lines changed

5 files changed

+16
-7
lines changed

Zend/tests/property_hooks/readonly_class_property_virtual_promoted.phpt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,4 +13,4 @@ readonly class Test {
1313

1414
?>
1515
--EXPECTF--
16-
Fatal error: Hooked virtual properties cannot be readonly in %s on line %d
16+
Fatal error: Hooked virtual properties may not be declared readonly in %s on line %d
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
--TEST--
2-
Virtual readonly property in interface throws
2+
Hooked properties in abstract classes cannot be readonly
33
--FILE--
44
<?php
55

@@ -8,4 +8,4 @@ abstract class Test {
88
}
99
?>
1010
--EXPECTF--
11-
Fatal error: Hooked virtual properties cannot be readonly in %s on line %d
11+
Fatal error: Hooked properties in abstract classes may not be declared readonly in %s on line %d

Zend/tests/property_hooks/readonly_property_virtual_in_class.phpt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,4 +10,4 @@ class Test {
1010
}
1111
?>
1212
--EXPECTF--
13-
Fatal error: Hooked virtual properties cannot be readonly in %s on line %d
13+
Fatal error: Hooked virtual properties may not be declared readonly in %s on line %d
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
--TEST--
2-
Virtual readonly property in interface throws
2+
Interface properties cannot be readonly
33
--FILE--
44
<?php
55

@@ -8,4 +8,4 @@ interface Test {
88
}
99
?>
1010
--EXPECTF--
11-
Fatal error: Hooked virtual properties cannot be readonly in %s on line %d
11+
Fatal error: Interface properties may not be declared readonly in %s on line %d

Zend/zend_compile.c

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8499,7 +8499,16 @@ static void zend_compile_property_hooks(
84998499

85008500
/* Allow hooks on backed readonly properties only. */
85018501
if ((prop_info->flags & (ZEND_ACC_READONLY|ZEND_ACC_VIRTUAL)) == (ZEND_ACC_READONLY|ZEND_ACC_VIRTUAL)) {
8502-
zend_error_noreturn(E_COMPILE_ERROR, "Hooked virtual properties cannot be readonly");
8502+
8503+
if (ce->ce_flags & ZEND_ACC_INTERFACE) {
8504+
zend_error_noreturn(E_COMPILE_ERROR, "Interface properties may not be declared readonly");
8505+
}
8506+
8507+
if (ce->ce_flags & (ZEND_ACC_IMPLICIT_ABSTRACT_CLASS|ZEND_ACC_EXPLICIT_ABSTRACT_CLASS)) {
8508+
zend_error_noreturn(E_COMPILE_ERROR, "Hooked properties in abstract classes may not be declared readonly");
8509+
}
8510+
8511+
zend_error_noreturn(E_COMPILE_ERROR, "Hooked virtual properties may not be declared readonly");
85038512
}
85048513

85058514
if (hooks->children == 0) {

0 commit comments

Comments
 (0)