| 2301 | class FirstClassCallableDemo |
| 2302 | { |
| 2303 | public function demo(): void |
| 2304 | { |
| 2305 | $src = new ScaffoldingFirstClassCallable(); |
| 2306 | |
| 2307 | $fun = makePen(...); |
| 2308 | $fun()->write(); // function reference → Closure returning Pen |
| 2309 | |
| 2310 | $orderFn = $src->dispatch(...); |
| 2311 | $orderFn()->write(); // instance method → Closure returning Pen |
| 2312 | |
| 2313 | $finder = Pen::make(...); |
| 2314 | $finder()->color(); // static method → Closure returning Pen |
| 2315 | |
| 2316 | $make = makePen(...); |
| 2317 | $pen = $make(); |
| 2318 | $pen->color(); // assigned result from callable invocation |
| 2319 | |
| 2320 | // Immediate invocation: method(...)() returns the method's return type |
| 2321 | makePen(...)()->write(); // function first-class callable invoked immediately |
| 2322 | Pen::make(...)()->color(); // static method first-class callable invoked immediately |
| 2323 | $src->dispatch(...)()->write(); // instance method first-class callable invoked immediately |
| 2324 | |
| 2325 | $immediate = Pen::make(...)(); |
| 2326 | $immediate->color(); // assigned result from immediate static callable invocation |
| 2327 | } |
| 2328 | } |
| 2329 | |
| 2330 | |