Table of Contents

About

Language - (Variable) Constant in PHP

Class

See Php - Object

Static Member

Class Constants differ from normal static variables in that you don't use the $ symbol to declare or use them.

class MyClass
{
    const CONSTANT = 'constant value';

    function showConstant() {
        echo  static::CONSTANT . "\n";
    }
}
echo  MyClass::CONSTANT;

Static Method

class MyClass
{

    static function showConstant() {
        echo 'constant value';
    }
}

echo MyClass::showConstant();

Abstract Static Method

Abstract static method

abstract class MyClass
{

   public static abstract function getStaticValue(): string;

   public static function getName(): string
    {
        return static::getStaticValue();
    }
    
}

Reflection

With reflection and the full path of the class (ie classname) and the constant function 1)

$staticValue = constant($className.'::'.$propertyName);

Define

see also: Php - Define (Global Constant)