Skip to content

Add lang.reflection.Closure to reflect callable closures - #52

Open
thekid wants to merge 10 commits into
mainfrom
feature/closure
Open

thekid wants to merge 10 commits into
mainfrom
feature/closure

Conversation

@thekid

@thekid thekid commented Nov 7, 2026 •

Copy link
Copy Markdown
Member

Example

use lang\reflection\Invocable;

$reflect= new Invocable(/** Handle */ fn(string $name): string => '@'.strtolower($name));
$reflect->name();              // null for anonymous functions like above
$reflect->comment();           // "Handle"
$reflect->annotations();       // lang.reflection.Annotations
$reflect->annotation($type);   // ?lang.reflection.Annotation
$reflect->parameters();        // lang.reflection.Parameters(size: 1)
$reflect->parameter(0);        // lang.reflection.Parameter(name: "name")
$reflect->parameter('name');   // -"-
$reflect->returns();           // lang.reflection.Constraint(type: 'string', present: true)
$reflect->invoke(['Test']);    // "@test"

Note: Annotations are only supported in PHP 8.0+!

@thekid

thekid commented Nov 9, 2026 •

Copy link
Copy Markdown
Member Author

Questions

  • Should this class be named Invocable instead? It matches the invoke() method and describes what the class reflects, whatever syntax created the value. Its only drawback is that it sounds a bit like an interface name.
  • Should we have $closure->invoke($bind, ['Test']) to match Routine::invoke()?

@thekid thekid added the enhancement New feature or request label Nov 9, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant