We have moved our forum to GitHub Discussions. For questions about Phalcon v3/v4/v5 you can visit here and for Phalcon v6 here.

[ASK] FindFirst sometimes return StdClass?

I was wondering why? because sometime my query using findfirst is returning a stdClass. The query itself only contain condition and binding. here is the query

Subscribers::findFirst([
            'conditions' => 'email_hash = :email_hash: AND is_deleted=0 AND status!=:status:',
            'bind' => [
                'email_hash' => $hash_email,
                'status' => Subscribers::UNSUBSCRIBE
            ]
        ]);

I am using phalcon 3.0.3, and PHP 7.0.16



85.5k

it should always return stdClass called Resultset :D, if there are no results the result will be false. You need to have an calss object, in order to be able to call methods from it after wards.

Well in this case findFirst will return always your Model class.

We need more info why this code returns stdclass, like call stack or something, i never had issue like this.



771

Currently we are tracking it using Sentry. The problem is, this is happening irregularly, so even a stack trace is not really helpful. Because when we try query manually, the record is indeed exist. We are extending the base Model class for all of our Models, but i don't think it's the problem. Also this is only happen in two Models(the second one happen more).

our latest stacktrace is

Error: Call to undefined method stdClass::update()
#7 /app/controllers/FrontendController.php(450): unsubSubmitAction
#6 [Anonymous function](0): callActionMethod
#5 [Anonymous function](0): _dispatch
#4 [Anonymous function](0): dispatch
#3 [Anonymous function](0): handle
#2 /app/library/Bootstrap.php(130): getOutput
#1 /app/library/Bootstrap.php(119): run
#0 /public/index.php(12): null

Idk, first time i see issue like this.