Skip to content

Commit b997327

Browse files
committed
Address review comments
1 parent 1dc58b2 commit b997327

14 files changed

+151
-34
lines changed

Zend/tests/bug49472.phpt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,4 +24,4 @@ new FooBar;
2424

2525
?>
2626
--EXPECTF--
27-
Fatal error: Cannot inherit previously-inherited or override constant c from interface ia in %s on line %d
27+
Fatal error: Cannot inherit previously-inherited or override constant FooBar::c from interface ia in %s on line %d
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
--TEST--
2+
Interface constants inherited from other interfaces can be redeclared
3+
--FILE--
4+
<?php
5+
6+
interface I1
7+
{
8+
const C = 1;
9+
}
10+
11+
interface I2
12+
{
13+
const C = 2;
14+
}
15+
16+
interface I3 extends I1, I2
17+
{
18+
const C = 3;
19+
}
20+
21+
?>
22+
--EXPECT--
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
--TEST--
2+
Class constants cannot be inherited from both a class and an interface
3+
--FILE--
4+
<?php
5+
6+
class C
7+
{
8+
const C = 1;
9+
}
10+
11+
interface I
12+
{
13+
const C = 1;
14+
}
15+
16+
class C2 extends C implements I
17+
{
18+
}
19+
20+
?>
21+
--EXPECTF--
22+
Fatal error: Cannot inherit previously-inherited or override constant C2::C from interface I in %s on line %d
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
--TEST--
2+
Interface constants cannot be inherited from other interfaces
3+
--FILE--
4+
<?php
5+
6+
interface I1
7+
{
8+
const C = 1;
9+
}
10+
11+
interface I2
12+
{
13+
const C = 2;
14+
}
15+
16+
interface I3 extends I1, I2
17+
{
18+
}
19+
20+
?>
21+
--EXPECTF--
22+
Fatal error: Cannot inherit previously-inherited or override constant I3::C from interface I2 in %s on line %d

Zend/tests/constants/final_constants/final_const3.phpt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,4 +10,4 @@ class Foo
1010

1111
?>
1212
--EXPECTF--
13-
Fatal error: Private constant Foo::A cannot be final as it is never overridden in %s on line %d
13+
Fatal error: Private constant Foo::A cannot be final as it is not visible to other classes in %s on line %d
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
--TEST--
2+
Class constants cannot be inherited from two different interfaces
3+
--FILE--
4+
<?php
5+
6+
interface I1
7+
{
8+
const C = 1;
9+
}
10+
11+
interface I2
12+
{
13+
const C = 1;
14+
}
15+
16+
class C implements I1, I2
17+
{
18+
}
19+
20+
?>
21+
--EXPECTF--
22+
Fatal error: Cannot inherit previously-inherited or override constant C::C from interface I2 in %s on line %d
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
--TEST--
2+
Class constants inherited from interfaces can be redeclared
3+
--FILE--
4+
<?php
5+
6+
interface I1
7+
{
8+
const C = 1;
9+
}
10+
11+
interface I2
12+
{
13+
const C = 2;
14+
}
15+
16+
class C implements I1, I2
17+
{
18+
const C = 3;
19+
}
20+
21+
?>
22+
--EXPECT--

Zend/tests/errmsg_025.phpt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,4 +17,4 @@ class test implements test1, test2 {
1717
echo "Done\n";
1818
?>
1919
--EXPECTF--
20-
Fatal error: Cannot inherit previously-inherited or override constant FOO from interface test2 in %s on line %d
20+
Fatal error: Cannot inherit previously-inherited or override constant test::FOO from interface test2 in %s on line %d

Zend/zend_API.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4331,12 +4331,12 @@ ZEND_API void zend_declare_property_stringl(zend_class_entry *ce, const char *na
43314331
}
43324332
/* }}} */
43334333

4334-
ZEND_API zend_class_constant *zend_declare_class_constant_ex(zend_class_entry *ce, zend_string *name, zval *value, int access_type, zend_string *doc_comment) /* {{{ */
4334+
ZEND_API zend_class_constant *zend_declare_class_constant_ex(zend_class_entry *ce, zend_string *name, zval *value, int flags, zend_string *doc_comment) /* {{{ */
43354335
{
43364336
zend_class_constant *c;
43374337

43384338
if (ce->ce_flags & ZEND_ACC_INTERFACE) {
4339-
if (!(access_type & ZEND_ACC_PUBLIC)) {
4339+
if (!(flags & ZEND_ACC_PUBLIC)) {
43404340
zend_error_noreturn(E_COMPILE_ERROR, "Access type for interface constant %s::%s must be public", ZSTR_VAL(ce->name), ZSTR_VAL(name));
43414341
}
43424342
}
@@ -4356,7 +4356,7 @@ ZEND_API zend_class_constant *zend_declare_class_constant_ex(zend_class_entry *c
43564356
c = zend_arena_alloc(&CG(arena), sizeof(zend_class_constant));
43574357
}
43584358
ZVAL_COPY_VALUE(&c->value, value);
4359-
ZEND_CLASS_CONST_FLAGS(c) = access_type;
4359+
ZEND_CLASS_CONST_FLAGS(c) = flags;
43604360
c->doc_comment = doc_comment;
43614361
c->attributes = NULL;
43624362
c->ce = ce;

Zend/zend_compile.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7306,7 +7306,7 @@ void zend_compile_class_const_decl(zend_ast *ast, uint32_t flags, zend_ast *attr
73067306

73077307
if (UNEXPECTED((flags & ZEND_ACC_PRIVATE) && (flags & ZEND_ACC_FINAL))) {
73087308
zend_error_noreturn(
7309-
E_COMPILE_ERROR, "Private constant %s::%s cannot be final as it is never overridden",
7309+
E_COMPILE_ERROR, "Private constant %s::%s cannot be final as it is not visible to other classes",
73107310
ZSTR_VAL(ce->name), ZSTR_VAL(name)
73117311
);
73127312
}

0 commit comments

Comments
 (0)