Skip to content

Refactor function scopes: Capturing and returning#61

Merged
thekid merged 4 commits into
masterfrom
refactor/function-scope
May 23, 2026
Merged

Refactor function scopes: Capturing and returning#61
thekid merged 4 commits into
masterfrom
refactor/function-scope

Conversation

@thekid
Copy link
Copy Markdown
Member

@thekid thekid commented May 23, 2026

Idea

What this applies to

Methods:

class T {
  public function name() => $this->name; // 🆕

  // Equivalent of
  // public function name() { return $this->name; }
}

Capturing closures:

fn($a, $b) => $a + $b;

// Equivalent of
// fn($a, $b) { return $a + $b; } // 🆕

Closures:

function($a, $b) => $a + $b; // 🆕

// Equivalent of
// function($a, $b) { return $a + $b; }

Functions:

function add($a, $b) => $a + $b; // 🆕

// Equivalent of
// function add($a, $b) { return $a + $b; }

public function children() { return $this->statements; }

/** Iteration support */
public function getIterator(): Traversable { yield from $this->statements; }
Copy link
Copy Markdown
Member Author

@thekid thekid May 23, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

With this the library is backwards-compatible for all instances using foreach / emitAll() on functions', closures' and methods' body member.

Comment on lines +1595 to +1599
// BC: Support deprecated arrow block syntax
if ('{' === $parse->token->value) {
trigger_error('Arrow block syntax `=> { ... }`', E_USER_DEPRECATED);
goto block;
}
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This can be removed in the next major release

@thekid thekid merged commit 72bfffe into master May 23, 2026
16 checks passed
@thekid
Copy link
Copy Markdown
Member Author

thekid commented May 23, 2026

@thekid thekid deleted the refactor/function-scope branch May 23, 2026 18:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant