1: <?php declare(strict_types=1);
2:
3: namespace PhpParser\Node\Stmt;
4:
5: use PhpParser\Node;
6:
7: class Foreach_ extends Node\Stmt {
8: /** @var Node\Expr Expression to iterate */
9: public Node\Expr $expr;
10: /** @var null|Node\Expr Variable to assign key to */
11: public ?Node\Expr $keyVar;
12: /** @var bool Whether to assign value by reference */
13: public bool $byRef;
14: /** @var Node\Expr Variable to assign value to */
15: public Node\Expr $valueVar;
16: /** @var Node\Stmt[] Statements */
17: public array $stmts;
18:
19: /**
20: * Constructs a foreach node.
21: *
22: * @param Node\Expr $expr Expression to iterate
23: * @param Node\Expr $valueVar Variable to assign value to
24: * @param array{
25: * keyVar?: Node\Expr|null,
26: * byRef?: bool,
27: * stmts?: Node\Stmt[],
28: * } $subNodes Array of the following optional subnodes:
29: * 'keyVar' => null : Variable to assign key to
30: * 'byRef' => false : Whether to assign value by reference
31: * 'stmts' => array(): Statements
32: * @param array<string, mixed> $attributes Additional attributes
33: */
34: public function __construct(Node\Expr $expr, Node\Expr $valueVar, array $subNodes = [], array $attributes = []) {
35: $this->attributes = $attributes;
36: $this->expr = $expr;
37: $this->keyVar = $subNodes['keyVar'] ?? null;
38: $this->byRef = $subNodes['byRef'] ?? false;
39: $this->valueVar = $valueVar;
40: $this->stmts = $subNodes['stmts'] ?? [];
41: }
42:
43: public function getSubNodeNames(): array {
44: return ['expr', 'keyVar', 'byRef', 'valueVar', 'stmts'];
45: }
46:
47: public function getType(): string {
48: return 'Stmt_Foreach';
49: }
50: }
51: