Skip to content

Commit 3c13864

Browse files
committed
Merge branch 'PHP-8.3' into PHP-8.4
* PHP-8.3: Relax final+private warning for trait methods with inherited final
2 parents 147e9c8 + a6a290d commit 3c13864

File tree

4 files changed

+33
-5
lines changed

4 files changed

+33
-5
lines changed

NEWS

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ PHP NEWS
1111
(nielsdos)
1212
. Fixed bug GH-17222 (__PROPERTY__ magic constant does not work in all
1313
constant expression contexts). (ilutov)
14+
. Fixed bug GH-17214 (Relax final+private warning for trait methods with
15+
inherited final). (ilutov)
1416

1517
- DOM:
1618
. Fixed bug GH-17397 (Assertion failure ext/dom/php_dom.c). (nielsdos)

Zend/tests/gh17214.phpt

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
--TEST--
2+
GH-17214: Relax final+private warning for trait methods with inherited final
3+
--FILE--
4+
<?php
5+
6+
trait MyTrait
7+
{
8+
final protected function someMethod(): void {}
9+
}
10+
11+
class Test
12+
{
13+
use MyTrait {
14+
someMethod as private anotherMethod;
15+
}
16+
17+
public function __construct()
18+
{
19+
$this->anotherMethod();
20+
}
21+
}
22+
23+
?>
24+
===DONE===
25+
--EXPECT--
26+
===DONE===

Zend/tests/traits/gh12854.phpt

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,6 @@ foreach (['pub', 'prot', 'priv', 'final1', 'final2', 'final3'] as $method) {
3939

4040
?>
4141
--EXPECTF--
42-
Warning: Private methods cannot be final as they are never overridden by other classes in %s on line %d
43-
4442
Warning: Private methods cannot be final as they are never overridden by other classes in %s on line %d
4543
--- Method: pub ---
4644
bool(true)

Zend/zend_inheritance.c

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2379,9 +2379,11 @@ static void zend_fixup_trait_method(zend_function *fn, zend_class_entry *ce) /*
23792379

23802380
static void zend_traits_check_private_final_inheritance(uint32_t original_fn_flags, zend_function *fn_copy, zend_string *name)
23812381
{
2382-
/* If the function was originally already private+final, then it will have already been warned about.
2383-
* If the function became private+final only after applying modifiers, we need to emit the same warning. */
2384-
if ((original_fn_flags & (ZEND_ACC_PRIVATE | ZEND_ACC_FINAL)) != (ZEND_ACC_PRIVATE | ZEND_ACC_FINAL)
2382+
/* If the function was originally already private+final, then it will have
2383+
* already been warned about. Only emit this error when the used trait method
2384+
* explicitly became final, avoiding errors for `as private` where it was
2385+
* already final. */
2386+
if (!(original_fn_flags & ZEND_ACC_FINAL)
23852387
&& (fn_copy->common.fn_flags & (ZEND_ACC_PRIVATE | ZEND_ACC_FINAL)) == (ZEND_ACC_PRIVATE | ZEND_ACC_FINAL)
23862388
&& !zend_string_equals_literal_ci(name, ZEND_CONSTRUCTOR_FUNC_NAME)) {
23872389
zend_error(E_COMPILE_WARNING, "Private methods cannot be final as they are never overridden by other classes");

0 commit comments

Comments
 (0)