Skip to content

Commit 924e7fc

Browse files
committed
Merge branch 'PHP-8.3'
* PHP-8.3: Fix GH-14480: Method visibility issue introduced in version 8.3.8 (#14484)
2 parents c7366cf + ee7d35c commit 924e7fc

File tree

2 files changed

+66
-4
lines changed

2 files changed

+66
-4
lines changed

Zend/tests/gh14480.phpt

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
--TEST--
2+
GH-14480: Method visibility issue
3+
--FILE--
4+
<?php
5+
trait PropertyHelperTrait
6+
{
7+
protected function splitPropertyParts(): void
8+
{
9+
echo "OK\n";
10+
}
11+
}
12+
13+
trait OrmPropertyHelperTrait
14+
{
15+
abstract protected function splitPropertyParts(): void;
16+
17+
protected function addJoinsForNestedProperty(): void
18+
{
19+
$this->splitPropertyParts();
20+
}
21+
}
22+
23+
trait SearchFilterTrait
24+
{
25+
use PropertyHelperTrait;
26+
}
27+
28+
abstract class AbstractFilter
29+
{
30+
use OrmPropertyHelperTrait, PropertyHelperTrait;
31+
32+
public function apply(): void
33+
{
34+
$this->filterProperty();
35+
}
36+
37+
abstract protected function filterProperty(): void;
38+
}
39+
40+
class SearchFilter extends AbstractFilter
41+
{
42+
use SearchFilterTrait;
43+
protected function filterProperty(): void
44+
{
45+
$this->addJoinsForNestedProperty();
46+
}
47+
}
48+
49+
class FilterExtension
50+
{
51+
public function applyToCollection(): void
52+
{
53+
(new SearchFilter())->apply();
54+
}
55+
}
56+
57+
(new FilterExtension)->applyToCollection();
58+
?>
59+
--EXPECT--
60+
OK

Zend/zend_inheritance.c

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2021,12 +2021,14 @@ static void zend_add_trait_method(zend_class_entry *ce, zend_string *name, zend_
20212021
if (check_inheritance) {
20222022
/* Inherited members are overridden by members inserted by traits.
20232023
* Check whether the trait method fulfills the inheritance requirements. */
2024+
uint32_t flags = ZEND_INHERITANCE_CHECK_PROTO | ZEND_INHERITANCE_CHECK_VISIBILITY;
2025+
if (!(existing_fn->common.scope->ce_flags & ZEND_ACC_TRAIT)) {
2026+
flags |= ZEND_INHERITANCE_SET_CHILD_CHANGED |ZEND_INHERITANCE_SET_CHILD_PROTO |
2027+
ZEND_INHERITANCE_RESET_CHILD_OVERRIDE;
2028+
}
20242029
do_inheritance_check_on_method(
20252030
fn, fixup_trait_scope(fn, ce), existing_fn, fixup_trait_scope(existing_fn, ce),
2026-
ce, NULL,
2027-
ZEND_INHERITANCE_CHECK_PROTO | ZEND_INHERITANCE_CHECK_VISIBILITY |
2028-
ZEND_INHERITANCE_SET_CHILD_CHANGED| ZEND_INHERITANCE_SET_CHILD_PROTO |
2029-
ZEND_INHERITANCE_RESET_CHILD_OVERRIDE);
2031+
ce, NULL, flags);
20302032
}
20312033
}
20322034
/* }}} */

0 commit comments

Comments
 (0)