Class Kitab\Compiler\IntermediateRepresentation\Constant
class Constant
{
public function __construct(string $name);
public function __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
public const VISIBILITY_PUBLIC = 0;
-
Represent a public constant.
public const VISIBILITY_PROTECTED = 1;
-
Represent a protected constant.
public const VISIBILITY_PRIVATE = 2;
-
Represent a private constant.
Attributes
public $visibility = self::VISIBILITY_PUBLIC;
-
The visibility of the attribute, represented by the
self::VISIBILITY_*
constants. public $name
-
Represent the name of the constant.
public $value = null;
-
A string containing only PHP code representing the value of the constant.
public $documentation = '';
-
Associated documentation of the constant.
Methods
-
public function __construct(string $name)
-
Allocate a constant with a name. This is the only mandatory information.
-
public function __toString(): string
-
Transform this intermediate representation into its PHP representation.
The original formatting is not kept. The applied formatting is designed for Kitab.