Class Kitab\Compiler\IntermediateRepresentation\Method
class Method
{
public function __construct(string $name);
public function __toString(): string;
}
A method intermediate representation.
A method is a function inside a class. Contrary to a function, it receives
an implicit $this argument representing the object (class instance),
except for static method. Just like a function, it has zero or many inputs,
and zero or one output. Each input is represented by a
Kitab\Compiler\IntermediateRepresentation\Parameter instance, while the
output is represented by a Kitab\Compiler\IntermediateRepresentation\Type
instance. A method also has a visiblity, can be abstract (if the class is
abstract), and can be final (cannot be overriden by a child class).
Examples
In this example, a new method f is created with 1 input: int $x, and
1 output: int.
$typeInt = new Kitab\Compiler\IntermediateRepresentation\Type();
$typeInt->name = 'int';
$input1 = new Kitab\Compiler\IntermediateRepresentation\Parameter('x');
$input1->type = $typeInt;
$output = $typeInt;
$method = new Kitab\Compiler\IntermediateRepresentation\Method('f');
$method->inputs[] = $input1;
$method->output = $output;
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 $lineStart = 0;-
Unsigned integer representing where the method declaration starts in the file. The file can be retrieved on the class containing this method.
public $lineEnd = 0;-
Unsigned integer representing where the entity declaration ends in the file. The file can retrieved on the class containing this method.
public $visibility = self::VISIBILITY_PUBLIC;-
The visibility of the method, represented by the
self::VISIBILITY_*constants. public $static = false;-
Represent whether the method is static or not.
A static method does not receive the implicit
$thisargument representing the current object. public $abstract = false;-
Represent whether the method is abstract or not.
An abstract method does not an implementation (body), it only provides a signature (inputs and output). If at least one method is abstract, the whole class must be marked as abstract.
public $final = false;-
Represent whether the method is final or not.
A final method cannot be overriden in a child class.
public $name-
The name of the method.
public $inputs = [];-
Collection of
Kitab\Compiler\IntermediateRepresentation\Parameterinstances. public $output = null;-
An output is a
Kitab\Compiler\IntermediateRepresentation\Typeinstance if any. public $documentation = null;-
Associated documentation of the entity as an instance of
Kitab\Compiler\IntermediateRepresentation\Documentation.
Methods
-
public function __construct(string $name) -
Allocate a new method with a name. This is the only mandatory information.
-
public function __toString(): string -
Transform the intermediate representation into its PHP representation.
The original formatting is not kept. The applied formatting is design for Kitab.