$reflectionProperty = new ReflectionProperty('ClassName', 'propertyName'); $visibility = Reflection::getModifierNames($reflectionProperty->getModifiers())[0]; // public, private, or protected $isStatic = $reflectionProperty->isStatic(); // true or false
$reflectionProperty = new ReflectionProperty('ClassName', 'propertyName'); $isReadonly = !$reflectionProperty->isPublic() || $reflectionProperty->isStatic();Brief Description: The first example gets the visibility and modifier flags of a property using getModifiers and getModifierNames methods. The second example determines if a property is read-only by checking if it is either private or static. Package Library: The ReflectionProperty class is part of PHP's core library and does not require any external package/library.