Skip to content

Commit

Permalink
Fix trait method visibility
Browse files Browse the repository at this point in the history
  • Loading branch information
ondrejmirtes committed Mar 23, 2024
1 parent 16919cb commit d6153d5
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions src/Reflection/ReflectionClass.php
Original file line number Diff line number Diff line change
Expand Up @@ -374,6 +374,8 @@ private function createMethodsFromTrait(ReflectionMethod $method): array
$methodHash = $this->methodHash($method->getImplementingClass()->getName(), $method->getName());

if (array_key_exists($methodHash, $this->traitsData['modifiers'])) {
$newModifierAst = $this->traitsData['modifiers'][$methodHash];
if ($this->traitsData['modifiers'][$methodHash] & ClassNode::VISIBILITY_MODIFIER_MASK) {
$methodModifiersWithoutVisibility = $methodModifiers;
if (($methodModifiers & CoreReflectionMethod::IS_PUBLIC) === CoreReflectionMethod::IS_PUBLIC) {
$methodModifiersWithoutVisibility -= CoreReflectionMethod::IS_PUBLIC;
Expand All @@ -384,7 +386,6 @@ private function createMethodsFromTrait(ReflectionMethod $method): array
if (($methodModifiers & CoreReflectionMethod::IS_PRIVATE) === CoreReflectionMethod::IS_PRIVATE) {
$methodModifiersWithoutVisibility -= CoreReflectionMethod::IS_PRIVATE;
}
$newModifierAst = $this->traitsData['modifiers'][$methodHash];
$newModifier = 0;
if (($newModifierAst & ClassNode::MODIFIER_PUBLIC) === ClassNode::MODIFIER_PUBLIC) {
$newModifier = CoreReflectionMethod::IS_PUBLIC;
Expand All @@ -395,10 +396,11 @@ private function createMethodsFromTrait(ReflectionMethod $method): array
if (($newModifierAst & ClassNode::MODIFIER_PRIVATE) === ClassNode::MODIFIER_PRIVATE) {
$newModifier = CoreReflectionMethod::IS_PRIVATE;
}
$methodModifiers = $methodModifiersWithoutVisibility | $newModifier;
}
if (($newModifierAst & ClassNode::MODIFIER_FINAL) === ClassNode::MODIFIER_FINAL) {
$newModifier = CoreReflectionMethod::IS_FINAL;
$methodModifiers |= CoreReflectionMethod::IS_FINAL;
}
$methodModifiers = $methodModifiersWithoutVisibility | $newModifier;
}

$createMethod = function (string|null $aliasMethodName) use ($method, $methodModifiers): ReflectionMethod {
Expand Down

0 comments on commit d6153d5

Please sign in to comment.