The ReflectionClassConstant class

- « ReflectionClass::__toString

- ReflectionClassConstant::__construct »

- PHP Manual
- Reflection
- The ReflectionClassConstant class

# The ReflectionClassConstant class

(PHP 7 >= 7.1.0, PHP 8)

## Introduction

The ReflectionClassConstant class reports information about a class constant.

## Class synopsis

class ReflectionClassConstant implements Reflector {
/* Constants */
public const int IS_PUBLIC;
public const int IS_PROTECTED;
public const int IS_PRIVATE;
public const int IS_FINAL;
/* Properties */
public string $name;
public string $class;
/* Methods */
public __construct(object|string `$class`, string `$constant`)
public static export(mixed `$class`, string `$name`, bool `$return` = ?): string
public getAttributes(?string `$name` = `null`, int `$flags` = 0): array
public getDeclaringClass(): ReflectionClass
public getDocComment(): string|false
public getModifiers(): int
public getName(): string
public getType(): ?ReflectionType
public getValue(): mixed
public hasType(): bool
public isDeprecated(): bool
public isEnumCase(): bool
public isFinal(): bool
public isPrivate(): bool
public isProtected(): bool
public isPublic(): bool
public __toString(): string
}

## Properties

name

  Name of the class constant. Read-only, throws ReflectionException in attempt to write.

class

  Name of the class where the class constant is defined. Read-only, throws ReflectionException in attempt to write.

## Predefined Constants

## ReflectionClassConstant Modifiers

`ReflectionClassConstant::IS_PUBLIC` int

  Indicates public constants. Prior to PHP 7.4.0, the value was `256`.

`ReflectionClassConstant::IS_PROTECTED` int

  Indicates protected constants. Prior to PHP 7.4.0, the value was `512`.

`ReflectionClassConstant::IS_PRIVATE` int

  Indicates private constants. Prior to PHP 7.4.0, the value was `1024`.

`ReflectionClassConstant::IS_FINAL` int

  Indicates final constants. Available as of PHP 8.1.0.

> Note:

> The values of these constants may change between PHP versions. It is recommended to always use the constants and not rely on the values directly.

## Changelog

Version | Description
--- | ---
8.4.0 | The class constants are now typed.
8.0.0 | ReflectionClassConstant::export() was removed.

## Table of Contents

- ReflectionClassConstant::__construct — Constructs a ReflectionClassConstant
- ReflectionClassConstant::export — Export
- ReflectionClassConstant::getAttributes — Gets Attributes
- ReflectionClassConstant::getDeclaringClass — Gets declaring class
- ReflectionClassConstant::getDocComment — Gets doc comments
- ReflectionClassConstant::getModifiers — Gets the class constant modifiers
- ReflectionClassConstant::getName — Get name of the constant
- ReflectionClassConstant::getType — Gets a class constant's type
- ReflectionClassConstant::getValue — Gets value
- ReflectionClassConstant::hasType — Checks if class constant has a type
- ReflectionClassConstant::isDeprecated — Checks if deprecated
- ReflectionClassConstant::isEnumCase — Checks if class constant is an Enum case
- ReflectionClassConstant::isFinal — Checks if class constant is final
- ReflectionClassConstant::isPrivate — Checks if class constant is private
- ReflectionClassConstant::isProtected — Checks if class constant is protected
- ReflectionClassConstant::isPublic — Checks if class constant is public
- ReflectionClassConstant::__toString — Returns the string representation of the ReflectionClassConstant object