Class Kitab\Compiler\IntermediateRepresentation\Attribute

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

An attribute intermediate representation.

An attribute is a property of a class like entity.

Examples

In this example, a new attribute foo is built, with a protected visibility, and a default value sets to 42.

$attribute             = new Kitab\Compiler\IntermediateRepresentation\Attribute('foo');
$attribute->visibility = $attribute::VISIBILITY_PROTECTED;
$attribute->default    = '42';

assert('protected $foo = 42' === (string) $attribute);

Constants

pub const VISIBILITY_PUBLIC = 0;

Represent a public attribute.

pub const VISIBILITY_PROTECTED = 1;

Represent a protected attribute.

pub const VISIBILITY_PRIVATE = 2;

Represent a private private.

Attributes

pub $visibility = self::VISIBILITY_PUBLIC;

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

pub $static = false;

Represent whether the attribute is static or not.

pub $name

Represent the name of the attribute, without the leading $.

pub $default = null;

A string containing only PHP code representing the default value of the attribute if any.

pub $documentation = '';

Associated documentation of the attribute.

Methods

pub fn __construct(string $name)

Allocate an attribute 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.