[PR #10870] Fix return type of getSingleScalarResult #12674

Closed
opened 2026-01-22 16:14:48 +01:00 by admin · 0 comments
Owner

Original Pull Request: https://github.com/doctrine/orm/pull/10870

State: closed
Merged: Yes


Doctrine\ORM\AbstractQuery::getSingleScalarResult() does not have null as a possible type of returned data while NoResultException is listed as one of the possible exceptions thrown.

However NoResultException is thrown only when hydration mode is not HYDRATE_SINGLE_SCALAR.

    public function getSingleResult($hydrationMode = null)
    {
        $result = $this->execute(null, $hydrationMode);

        if ($this->_hydrationMode !== self::HYDRATE_SINGLE_SCALAR && ! $result) {
            throw new NoResultException();
        }

In getSingleScalarResult hydration mode was set to HYDRATE_SINGLE_SCALAR via Doctrine\ORM\AbstractQuery::execute() which makes it impossible to throw that particular type of exception.

**Original Pull Request:** https://github.com/doctrine/orm/pull/10870 **State:** closed **Merged:** Yes --- `Doctrine\ORM\AbstractQuery::getSingleScalarResult()` does not have `null` as a possible type of returned data while `NoResultException` is listed as one of the possible exceptions thrown. However `NoResultException` is thrown only when hydration mode is not `HYDRATE_SINGLE_SCALAR`. ```php public function getSingleResult($hydrationMode = null) { $result = $this->execute(null, $hydrationMode); if ($this->_hydrationMode !== self::HYDRATE_SINGLE_SCALAR && ! $result) { throw new NoResultException(); } ``` In `getSingleScalarResult` hydration mode was set to `HYDRATE_SINGLE_SCALAR` via `Doctrine\ORM\AbstractQuery::execute()` which makes it impossible to throw that particular type of exception.
admin added the pull-request label 2026-01-22 16:14:48 +01:00
admin closed this issue 2026-01-22 16:14:49 +01:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: doctrine/archived-orm#12674