PHP TypeLang Help

TypeStatement

A TypeStatement is an AST node that represents a complete and independent description of a type. Each implementation of the type statement contains one $offset property meaning the offset in bytes from the beginning of the passed type definition string where the specified node is located.

Literals

Each literal implements class TypeLang\Parser\Node\Literal\LiteralNode and contains one public field $raw containing the string representation of the parsed data.

In addition, some literal nodes may contain parsed values of different types, which are located in the $value field.

Thus, if we parse, for example, TrUe string, the literal instance will contain:

var_dump($literal->raw); // string("TrUe") var_dump($literal->value); // bool(true)
  • BoolLiteralNode - Represents a true or false literal values

  • FloatLiteralNode - Represents a float (i.e., 0.42, -1.2, etc.) literal values

  • IntLiteralNode - Represents an integer (i.e., 42, -12, etc.) literal values

    • An integer values (IntLiteralNode) additionally contain a $decimal property, which contains the string decimal value of the parsed string

  • NullLiteralNode - Represents null literal value

    • This node does not contain $value property

  • StringLiteralNode - Represents any string (i.e., 'string', "str\ning", etc.) literal values

  • VariableLiteralNode - Represents any PHP variable (i.e., $var, $this, etc.) literal values

Named Types

Named types are a standalone type that contains a name. For example, a type declaration such as int is a named type, but int|bool is not, it is a union type of two named types.

Each named type contains one required property $name and two optional ones (can be null):

  • $arguments - List of type's template arguments

  • $fields - List of type's shape fields

var_dump($stmt->name); var_dump($stmt->arguments); var_dump($stmt->fields);
string("array") null null
var_dump($stmt->name); var_dump($stmt->arguments); var_dump($stmt->fields);
string("array") object(TemplateArgumentsListNode) null
var_dump($stmt->name); var_dump($stmt->arguments); var_dump($stmt->fields);
string("array") null object(FieldsListNode)
var_dump($stmt->name); var_dump($stmt->arguments); var_dump($stmt->fields);
string("array") object(TemplateArgumentsListNode) object(FieldsListNode)
06 November 2025