bitwise-operators/utils-reflection

A set of utility function for use with PHP Reflection

Installs: 0

Dependents: 0

Suggesters: 0

Security: 0

Stars: 0

Watchers: 0

Forks: 0

Open Issues: 0

pkg:composer/bitwise-operators/utils-reflection

1.0.0 2025-12-05 16:02 UTC

This package is auto-updated.

Last update: 2025-12-05 16:11:54 UTC


README

A set of utility function for use with PHP Reflection.

Available functions

The following functions are supplied

All functions live in the BitwiseOperators\Reflection namespace.

Checking if a class is an Attribute implementation

is_attribute_class(): bool

Arguments:

  • class: object | string

Checking if an attribute is set on a PHP entity

The following functions check if an attribute is set on the supplied class, function, method or property.

For all functions, the attribute can be supplied as a class-string or as a ReflectionAttribute object for the desired attribute.

Attributes are checked in instance-mode, so descendant implementations of the supplied attribute also return true

If no attribute class is specified, the functions return true when the subject has any attributes.

class_has_attribute(): bool

Arguments:

  • class: object | string,
  • attribute: null | string | ReflectionAttribute

Checks the supplied class for attributes $attribute.

The class can be supplied as an object, a string, or as a ReflectionClass containing the subject.

function_has_attribute(): bool

Arguments:

  • function: ReflectionFunctionAbstract | string,
  • attribute: null | string | ReflectionAttribute

Checks the supplied function for attributes.

The function can be supplied as a string or as a ReflectionFunctionAbstract containing the subject.

Make sure the function is fully namespaced if applicable.

method_has_attribute(): bool

This function has two possible signatures:

Arguments:

  • class: object | string
  • method: ReflectionMethod | string
  • attribute: null | string | ReflectionAttribute

The method can be supplied as a combination of class and method-name, where the class arguments follow the same requirements as for the class_has_attributes function. The method can be either a string or a ReflectionMethod containing the method.

When using a ReflectionMethod object, the class argument can be omitted completely:

Arguments:

  • method: ReflectionMethod
  • attribute: null | string | ReflectionAttribute

property_has_attribute(): bool

This function has two possible signatures:

Arguments:

  • class: object | string
  • property: ReflectionProperty | string
  • attribute: null | string | ReflectionAttribute

The property can be supplied as a combination of class and property-name, where the class arguments follow the same requirements as for the class_has_attributes function. The property can be either a string or a ReflectionProperty containing the method.

When using a ReflectionProperty object, the class argument can be omitted completely:

Arguments:

  • property: ReflectionProperty
  • attribute: null | string | ReflectionAttribute