4

I have the error as said in title in the following code (guzzle http lib) please tell me how to fix it manually. I have no idea about function() use () construct to be honest so dont know how to fix it.

public function once($eventName, callable $listener, $priority = 0) {
    $onceListener = function (
        EventInterface $event,
        $eventName
    ) use (&$onceListener, $eventName, $listener, $priority) {
        $this->removeListener($eventName, $onceListener);
        $listener($event, $eventName, $this);
    };

    $this->on($eventName, $onceListener, $priority);
}

Problem is with $eventName after use( construct.

Valor_
  • 3,461
  • 9
  • 60
  • 109
luky
  • 2,263
  • 3
  • 22
  • 40
  • 3
    You are trying to use 2 variables with the same name $eventName. Rename your parameters. Ex: `function ( EventInterface $event, $eventName2 ) use (...){}` – bakis Feb 09 '19 at 19:27
  • aha ok thx...... – luky Feb 09 '19 at 19:29
  • 1
    Read more about anonymous functions here: http://php.net/manual/en/functions.anonymous.php – bakis Feb 09 '19 at 19:29

1 Answers1

3

I had the same issue, which was caused by incompatability between an older guzzle version and php 7. By updating guzzle to version 5.3.4 this issue was fixed.

$ composer update guzzlehttp/guzzle

Resulting in

Loading composer repositories with package information
Updating dependencies (including require-dev)
Package operations: 0 installs, 1 update, 0 removals
  - Updating guzzlehttp/guzzle (5.3.0 => 5.3.4): Downloading (100%)
Writing lock file
Generating autoload files
PtrTon
  • 3,705
  • 2
  • 14
  • 24