Class Kitab\Compiler\IntermediateRepresentation\Parameter
class Parameter
{
public function __construct(string $name);
public function __toString(): string;
}
A parameter intermediate representation.
A parameter of a function (or method) receives an argument. It takes the form of a variable with a type and a default value. A parameter can be variadic if it is in the last position of the list of parameters: It means it will receive all extra arguments given to the function.
Examples
The following example represent the parameter int $foo = 42
:
$typeInt = new Kitab\Compiler\IntermediateRepresentation\Type();
$typeInt->name = 'int';
$parameter = new Kitab\Compiler\IntermediateRepresentation\Parameter('x');
$parameter->type = $typeInt;
$parameter->name = 'foo';
$parameter->value = '42';
Attributes
public $type = null;
-
Type of the parameter. See
Kitab\Compiler\IntermediateRepresentation\Type
. public $name
-
Name of the parameter, without the leading
$
. public $variadic = false;
-
A variadic parameter receives all the extra arguments given to the function. It must be the last parameter of the list of parameters. It is represented by the
...
symbol. public $value = null;
-
A string containing only PHP code representing the default value of the parameter if any. A default value for the
Methods
-
public function __construct(string $name)
-
Allocate a parameter 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 designed for Kitab.