1
0
mirror of https://github.com/php/php-src.git synced 2026-03-24 00:02:20 +01:00
Files
archived-php-src/Zend/tests/closures/bug80929.phpt
twosee c0b1bdcdc3 Fixed bug #80929
The function name should be kept if Closure was created from the function which is marked as ZEND_ACC_CALL_VIA_TRAMPOLINE, because it is not a one-time thing and it may be called multiple times.

Closes GH-6867.
2021-04-16 09:48:36 +08:00

57 lines
1.1 KiB
PHP

--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