xref: /PHP-8.3/Zend/tests/closures/bug80929.phpt (revision c0b1bdcd)
1--TEST--
2Bug #80929: Method name corruption related to zend_closure_call_magic
3--FILE--
4<?php
5class DefaultListener
6{
7    public function handleDefaultEvent($event) { }
8}
9
10class SubscriberProxy
11{
12    private array $subscribedEvents;
13    private object $subscriber;
14    private Closure $listener;
15
16    public function __construct(array $subscribedEvents, object $subscriber)
17    {
18        $this->subscribedEvents = $subscribedEvents;
19        $this->subscriber = $subscriber;
20        foreach ($this->subscribedEvents as $eventName => $params) {
21            $this->listener = Closure::fromCallable([$this, $params]);
22        }
23    }
24
25    public function __call(string $name, array $arguments)
26    {
27        return $this->subscriber->$name(...$arguments);
28    }
29
30    public function dispatch($event, string $eventName)
31    {
32        ($this->listener)($event, $eventName, null);
33    }
34}
35
36$proxy = new SubscriberProxy(
37    ['defaultEvent' => 'handleDefaultEvent'],
38    new DefaultListener()
39);
40
41for ($i = 0; $i < 10; $i++) {
42    echo $i . PHP_EOL;
43    $proxy->dispatch(null, 'defaultEvent');
44}
45?>
46--EXPECT--
470
481
492
503
514
525
536
547
558
569
57