Search code examples
phpreactphp

ReactPHP get_class() expects parameter 1 to be object, string given


I am getting this error code:

PHP Warning: get_class() expects parameter 1 to be object, string given in /phalcon/vendor/clue/block-react/src/functions.php on line 90 PHP Fatal error: Uncaught UnexpectedValueException: Promise rejected with unexpected value of type in /phalcon/vendor/clue/block-react/src/functions.php:89 Stack trace:

  • 0 /phalcon/vendor/clue/block-react/src/functions.php(198): Clue\React\Block\await(NULL, Object(React\EventLoop\StreamSelectLoop), NULL)
  • 1 /phalcon/app/tasks/RunTask.php(96): Clue\React\Block\awaitAll(NULL, Object(React\EventLoop\StreamSelectLoop))

I'm building my promises with the following code:

$promises[] = $this->getTrades($rule->id, $exchange->id)
                ->then(
                    function ($trades) use ($handleTrades) {
                        foreach ($trades as $trade) {
                            $handleTrades[] = $trade;
                        }
                    }
                );

The function is like this:

private function getTrades($rule, $exchange) {
    $deferred = new React\Promise\Deferred();

    //...

    if (empty($trades->count())) {
        $deferred->reject("No trades found for rule $rule");
    } else {
        $deferred->resolve($trades);
    }

    return $deferred->promise();
}

How do I solve this?


Solution

  • As Furgas mentioned above I needed to add the error handling function in the promise.