1
0
mirror of https://github.com/php/php-src.git synced 2026-03-24 00:02:20 +01:00

Merge branch 'PHP-8.3' into PHP-8.4

* PHP-8.3:
  Relax final+private warning for trait methods with inherited final
This commit is contained in:
Ilija Tovilo
2025-01-13 16:46:43 +01:00
4 changed files with 33 additions and 5 deletions

2
NEWS
View File

@@ -11,6 +11,8 @@ PHP NEWS
(nielsdos)
. Fixed bug GH-17222 (__PROPERTY__ magic constant does not work in all
constant expression contexts). (ilutov)
. Fixed bug GH-17214 (Relax final+private warning for trait methods with
inherited final). (ilutov)
- DOM:
. Fixed bug GH-17397 (Assertion failure ext/dom/php_dom.c). (nielsdos)

26
Zend/tests/gh17214.phpt Normal file
View File

@@ -0,0 +1,26 @@
--TEST--
GH-17214: Relax final+private warning for trait methods with inherited final
--FILE--
<?php
trait MyTrait
{
final protected function someMethod(): void {}
}
class Test
{
use MyTrait {
someMethod as private anotherMethod;
}
public function __construct()
{
$this->anotherMethod();
}
}
?>
===DONE===
--EXPECT--
===DONE===

View File

@@ -39,8 +39,6 @@ foreach (['pub', 'prot', 'priv', 'final1', 'final2', 'final3'] as $method) {
?>
--EXPECTF--
Warning: Private methods cannot be final as they are never overridden by other classes in %s on line %d
Warning: Private methods cannot be final as they are never overridden by other classes in %s on line %d
--- Method: pub ---
bool(true)

View File

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