Answer the question
In order to leave comments, you need to log in
Why is Fatal error: Function name must be a string in returned?
I'm trying to add middleware support to my project by adding a pipeline, but an error is returned:
Function name must be a string in /home/ugwwspov/bot.qeo.su/hardown/vk/VK/Pipeline/Pipeline.php on line 29
<?php
class Pipeline
{
/**
* @var callable[]
*/
private $stages;
public function pipe(callable $stage)
{
$this->stages[] = $stage;
return $this;
}
public function __invoke($context, $next = null)
{
$this->start($context, $next);
}
public function start($context, $next = null)
{
if(!$current = array_shift($this->stages) and $next != null)
{
$next($context);
}
return $current($context, function ($context) use ($next) {
return $this($context, $next);
});
}
}
Answer the question
In order to leave comments, you need to log in
Either you have a PHP server below version 5.3.0 (does not allow you to use the __invoke magic method).
Or try adding $this to the closure (where use is).
return $current($context, function ($context) use ($this, $next) {
return $this($context, $next);
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question