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

Check for a boolean seems to convert to boolean

I'm using a check to see if findFirst actually retrieves data. I always use it like this:

    $question = Questions::findFirst("uuid = '".$question."'");
    if (!$question) {
        return $this->respondWithError('No question was found');
    }

Now, this always worked for me. But today I found that the code above was triggering the error response, even though the question I was fetching existed. I also found out that if I removed the check, everything would work. I then placed a var_dump() after findFirst but before the check and I placed on inside the if-statement. The first one dumped the actual model, the second one dumped a boolean. Anyone have any ideas as to what's going on here?

Tested exact scenario and is working as intended. Maybe phalcon/php version?

Also this ("uuid = '".$question."'"); can lead to sql injection, not sure what you do with $question value before tho. Better bind the parameters to be safe ;)

Oh, they're already cleaned and everything. So I'm not really concerned about that. The strange part is that this is happening on no other places in the application. Just this one part.

This is a stretch, but maybe because you're overwriting the variable? Make the assignment assign to $Question and then what happens?