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 23 additions and 21 deletions.
44 changes: 23 additions & 21 deletions src/Reflection/ReflectionClass.php
Original file line number Diff line number Diff line change
Expand Up @@ -374,31 +374,33 @@ private function createMethodsFromTrait(ReflectionMethod $method): array
$methodHash = $this->methodHash($method->getImplementingClass()->getName(), $method->getName());

if (array_key_exists($methodHash, $this->traitsData['modifiers'])) {
$methodModifiersWithoutVisibility = $methodModifiers;
if (($methodModifiers & CoreReflectionMethod::IS_PUBLIC) === CoreReflectionMethod::IS_PUBLIC) {
$methodModifiersWithoutVisibility -= CoreReflectionMethod::IS_PUBLIC;
}
if (($methodModifiers & CoreReflectionMethod::IS_PROTECTED) === CoreReflectionMethod::IS_PROTECTED) {
$methodModifiersWithoutVisibility -= CoreReflectionMethod::IS_PROTECTED;
}
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;
}
if (($newModifierAst & ClassNode::MODIFIER_PROTECTED) === ClassNode::MODIFIER_PROTECTED) {
$newModifier = CoreReflectionMethod::IS_PROTECTED;
}
if (($newModifierAst & ClassNode::MODIFIER_PRIVATE) === ClassNode::MODIFIER_PRIVATE) {
$newModifier = CoreReflectionMethod::IS_PRIVATE;
if ($this->traitsData['modifiers'][$methodHash] & ClassNode::VISIBILITY_MODIFIER_MASK) {
$methodModifiersWithoutVisibility = $methodModifiers;
if (($methodModifiers & CoreReflectionMethod::IS_PUBLIC) === CoreReflectionMethod::IS_PUBLIC) {
$methodModifiersWithoutVisibility -= CoreReflectionMethod::IS_PUBLIC;
}
if (($methodModifiers & CoreReflectionMethod::IS_PROTECTED) === CoreReflectionMethod::IS_PROTECTED) {
$methodModifiersWithoutVisibility -= CoreReflectionMethod::IS_PROTECTED;
}
if (($methodModifiers & CoreReflectionMethod::IS_PRIVATE) === CoreReflectionMethod::IS_PRIVATE) {
$methodModifiersWithoutVisibility -= CoreReflectionMethod::IS_PRIVATE;
}
$newModifier = 0;
if (($newModifierAst & ClassNode::MODIFIER_PUBLIC) === ClassNode::MODIFIER_PUBLIC) {
$newModifier = CoreReflectionMethod::IS_PUBLIC;
}
if (($newModifierAst & ClassNode::MODIFIER_PROTECTED) === ClassNode::MODIFIER_PROTECTED) {
$newModifier = CoreReflectionMethod::IS_PROTECTED;
}
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.