File size: 1,122 Bytes
1e94262
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
--TEST--
Bug #80929: Method name corruption related to zend_closure_call_magic
--FILE--
<?php
class DefaultListener
{
    public function handleDefaultEvent($event) { }
}

class SubscriberProxy
{
    private array $subscribedEvents;
    private object $subscriber;
    private Closure $listener;

    public function __construct(array $subscribedEvents, object $subscriber)
    {
        $this->subscribedEvents = $subscribedEvents;
        $this->subscriber = $subscriber;
        foreach ($this->subscribedEvents as $eventName => $params) {
            $this->listener = Closure::fromCallable([$this, $params]);
        }
    }

    public function __call(string $name, array $arguments)
    {
        return $this->subscriber->$name(...$arguments);
    }

    public function dispatch($event, string $eventName)
    {
        ($this->listener)($event, $eventName, null);
    }
}

$proxy = new SubscriberProxy(
    ['defaultEvent' => 'handleDefaultEvent'],
    new DefaultListener()
);

for ($i = 0; $i < 10; $i++) {
    echo $i . PHP_EOL;
    $proxy->dispatch(null, 'defaultEvent');
}
?>
--EXPECT--
0
1
2
3
4
5
6
7
8
9