Class Attributes

PHP Class with Class Attributes

<?php

declare(strict_types=1);

#[TestAttribute11(["key1" => "key1 value"])]
#[TestAttribute12(10.13)]
#[TestAttribute13(123)]
#[TestAttribute14()]
#[TestAttribute15(["value1", "value2"])]
class Abc
{
    // rest of the codes
}

Initialize the Attributes Reader

<?php

declare(strict_types=1);

use \AntonDPerera\PHPAttributesReader\AttributesReader;

$class = Abc::class;

$attributes_reader = AttributesReader($class);

Available functions for Class Attributes

public function hasClassAttributes(): bool

Returns true or false based on availability of Class attributes.

public function getClassAttributes(): array

Returns array of attributes. Each item on Array will be an instance of Attribute class

\AntonDPerera\PHPAttributesReader\Attribute

Refer Attribute class Reference documentation for more details.

public function getClassAttribute(string $attribute_name): Attribute | ClassAttributeNotFoundException
  1. Throws ClassAttributeNotFoundException when the given attribute name is not available as a Class Attribute. \AntonDPerera\PHPAttributesReader\Exceptions\ClassAttributeNotFoundException

  2. Returns an instance of Attribute if there is a Class attribute with the given name. \AntonDPerera\PHPAttributesReader\Attribute

Last updated