Skip to content

Commit 86b93bc

Browse files
authored
Fix GH-14480: Method visibility issue introduced in version 8.3.8 (#14484)
1 parent da769be commit 86b93bc

File tree

2 files changed

+65
-3
lines changed

2 files changed

+65
-3
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: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1933,11 +1933,13 @@ static void zend_add_trait_method(zend_class_entry *ce, zend_string *name, zend_
19331933
if (check_inheritance) {
19341934
/* Inherited members are overridden by members inserted by traits.
19351935
* Check whether the trait method fulfills the inheritance requirements. */
1936+
uint32_t flags = ZEND_INHERITANCE_CHECK_PROTO | ZEND_INHERITANCE_CHECK_VISIBILITY;
1937+
if (!(existing_fn->common.scope->ce_flags & ZEND_ACC_TRAIT)) {
1938+
flags |= ZEND_INHERITANCE_SET_CHILD_CHANGED |ZEND_INHERITANCE_SET_CHILD_PROTO;
1939+
}
19361940
do_inheritance_check_on_method(
19371941
fn, fixup_trait_scope(fn, ce), existing_fn, fixup_trait_scope(existing_fn, ce),
1938-
ce, NULL,
1939-
ZEND_INHERITANCE_CHECK_PROTO | ZEND_INHERITANCE_CHECK_VISIBILITY |
1940-
ZEND_INHERITANCE_SET_CHILD_CHANGED| ZEND_INHERITANCE_SET_CHILD_PROTO);
1942+
ce, NULL, flags);
19411943
}
19421944
}
19431945
/* }}} */

0 commit comments

Comments
 (0)