Class Kitab\Compiler\IntermediateRepresentation\Type
class Type
{
public function __toString(): string;
}
A type intermediate representation.
A type has a name. It can represent a value passed by copy or by reference. It can be nullable, i.e. null value can be considered as valid.
Because values in PHP are represented by union types (many types), the type of a value can be undeclared (and decided at runtime). Thus, a type can have no name in this intermediate representation.
Examples
The following example builds a nullable reference type T.
$type = new Kitab\Compiler\IntermediateRepresentation\Type();
$type->name = 'T';
$type->reference = true;
$type->nullable = true;
assert('?T &' === (string) $type);
Attributes
public $reference = false;-
If
true, the type will represent a value passed by reference, else —false—, a value passed by copy. public $nullable = false;-
A nullable type accepts the
nullvalue as valid. For instance the typestringdoes not accept thenullvalue, but?stringwill accept both strings and thenullvalue. public $name = null;-
Name of the type.
Methods
-
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.
Examples
$type = new Kitab\Compiler\IntermediateRepresentation\Type(); $type->name = 'T'; assert('T ' === (string) $type);