Skip to content

Commit 23d0272

Browse files
committed
Removed mutual modifier restriction for abstract static class.
Improved a couple of static class tests per feedback.
1 parent f6916fe commit 23d0272

File tree

5 files changed

+42
-15
lines changed

5 files changed

+42
-15
lines changed

Zend/tests/static_class/inherit_static_class.phpt

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,15 @@ Tests that a static class can inherit from another static class
33
--FILE--
44
<?php
55

6-
static class C {}
6+
static class C {
7+
static function F() {
8+
echo 'OK';
9+
}
10+
}
711

812
static class C2 extends C {}
13+
14+
C2::F();
915
?>
1016
--EXPECT--
17+
OK
Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,19 @@
11
--TEST--
2-
Tests that a static class cannot be marked abstract
2+
Tests that a static class can be marked abstract
33
--FILE--
44
<?php
55

6-
abstract static class C {}
6+
abstract static class C {
7+
abstract static function F();
8+
}
9+
10+
static class C2 extends C {
11+
static function F() {
12+
echo 'OK';
13+
}
14+
}
15+
16+
C2::F();
717
?>
8-
--EXPECTF--
9-
Fatal error: Cannot use the static modifier on an abstract class in %s on line %d
18+
--EXPECT--
19+
OK
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
--TEST--
2+
Tests that the AST export of a static class includes the static modifier
3+
--FILE--
4+
<?php
5+
6+
assert(false && function () {
7+
static class C {}
8+
});
9+
?>
10+
--EXPECTF--
11+
%a
12+
%wstatic class C {%w}
13+
%a

Zend/tests/static_class/static_final_class.phpt

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,8 @@ Tests that a static class can be marked final
44
<?php
55

66
final static class C {}
7+
8+
static class C2 extends C {}
79
?>
8-
--EXPECT--
10+
--EXPECTF--
11+
Fatal error: Class C2 cannot extend final class C in %s on line %d

Zend/zend_compile.c

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -944,15 +944,9 @@ uint32_t zend_add_class_modifier(uint32_t flags, uint32_t new_flag) /* {{{ */
944944
"Cannot use the final modifier on an abstract class", 0);
945945
return 0;
946946
}
947-
if (new_flags & ZEND_ACC_STATIC) {
948-
if (new_flags & ZEND_ACC_EXPLICIT_ABSTRACT_CLASS) {
949-
zend_throw_exception(zend_ce_compile_error, "Cannot use the static modifier on an abstract class", 0);
950-
return 0;
951-
}
952-
if (new_flags & ZEND_ACC_READONLY_CLASS) {
953-
zend_throw_exception(zend_ce_compile_error, "Cannot use the static modifier on a readonly class", 0);
954-
return 0;
955-
}
947+
if ((new_flags & ZEND_ACC_STATIC) && (new_flags & ZEND_ACC_READONLY_CLASS)) {
948+
zend_throw_exception(zend_ce_compile_error, "Cannot use the static modifier on a readonly class", 0);
949+
return 0;
956950
}
957951
if ((flags & ZEND_ACC_STATIC) && (new_flag & ZEND_ACC_STATIC)) {
958952
zend_throw_exception(zend_ce_compile_error,

0 commit comments

Comments
 (0)