Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
factormaarten opened this issue Jul 24, 2018 · 2 comments · Fixed by #42
Closed

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

factormaarten opened this issue Jul 24, 2018 · 2 comments · Fixed by #42
Labels
Milestone

Comments

@factormaarten
Copy link

factormaarten commented Jul 24, 2018

Hi there,

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?

@Furgas
Copy link
Contributor

Furgas commented Jul 24, 2018

Added a pull request for a get_class warning issue. As for your actual problem, I've answered on Stackoverflow.

@clue clue added the bug label Jul 24, 2018
@clue clue added this to the v1.3.1 milestone Jul 24, 2018
@clue
Copy link
Owner

clue commented Jul 24, 2018

@mpjraaij Thank you for reporting! This is indeed a small bug in this library, @Furgas has just filed PR #37 to fix this 👍

That being said, this only happens if you reject a promise with a scalar value instead of a an Exception. There's ongoing discussion to enforce Exception objects in the future, so I suppose it's a good idea to update your code to use an Exception just in case: reactphp/promise#46

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants