Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions src/main/php/lang/meta/MetaInformation.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,23 @@ public function propertyComment($reflect) {
}
}

/**
* Returns modifiers for a given property, including non-declared
*
* @param \ReflectionProperty $reflect
* @return int
*/
public function propertyModifiers($reflect) {
$name= $reflect->getDeclaringClass()->name;
$c= \xp::$cn[$name] ?? strtr($name, '\\', '.');
if ($meta= \xp::$meta[$c][0][$reflect->getName()][DETAIL_ARGUMENTS] ?? null) {
return $reflect->getModifiers() | (int)$meta[0];
} else {
$tags= $this->tags($reflect);
return $reflect->getModifiers() | (isset($tags['final']) ? MODIFIER_FINAL : 0);
}
}

/**
* Returns annotation map (type => arguments) for a given method
*
Expand Down
2 changes: 1 addition & 1 deletion src/main/php/lang/reflection/Property.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ public function modifiers($hook= null) {
];

// Readonly implies protected(set)
$bits= $this->reflect->getModifiers();
$bits= Reflection::meta()->propertyModifiers($this->reflect);
$bits & Modifiers::IS_READONLY && $bits|= Modifiers::IS_PROTECTED_SET;

switch ($hook) {
Expand Down
16 changes: 16 additions & 0 deletions src/test/php/lang/reflection/unittest/PropertiesTest.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,22 @@ public function modifiers() {
);
}

#[Test]
public function modifiers_tagged_final() {
Assert::equals(
new Modifiers(['public', 'final']),
$this->declare('{ /** @final */ public $fixture; }')->property('fixture')->modifiers()
);
}

#[Test, Runtime(php: '>=8.4')]
public function modifiers_declared_final() {
Assert::equals(
new Modifiers(['public', 'final']),
$this->declare('{ public final $fixture; }')->property('fixture')->modifiers()
);
}

#[Test, Values(['public', 'protected', 'private'])]
public function get_modifiers($modifier) {
Assert::equals(
Expand Down
Loading