Class Kitab\Compiler\IntermediateRepresentation\Constant

class Constant
{
    pub fn __construct(string $name);
    pub fn __toString(): string;
}

A constant intermediate representation.

A constant is a property of a class entity.

Examples

In this example, a new constant FOO is built, with a protected visibility, and a value sets to 42.

$constant             = new Kitab\Compiler\IntermediateRepresentation\Constant('FOO');
$constant->visibility = $constant::VISIBILITY_PROTECTED;
$constant->value      = '42';

assert('protected const FOO = 42' === (string) $constant);

Constants

pub const VISIBILITY_PUBLIC = 0;

Represent a public constant.

pub const VISIBILITY_PROTECTED = 1;

Represent a protected constant.

pub const VISIBILITY_PRIVATE = 2;

Represent a private constant.

Attributes

pub $visibility = self::VISIBILITY_PUBLIC;

The visibility of the attribute, represented by the self::VISIBILITY_* constants.

pub $name

Represent the name of the constant.

pub $value = null;

A string containing only PHP code representing the value of the constant.

pub $documentation = '';

Associated documentation of the constant.

Methods

pub fn __construct(string $name)

Allocate a constant with a name. This is the only mandatory information.

pub fn __toString(): string

Transform this intermediate representation into its PHP representation.

The original formatting is not kept. The applied formatting is designed for Kitab.