[PR #5842] Fixing setResultCacheProfile when handling null profile #9752

Open
opened 2026-01-22 16:05:18 +01:00 by admin · 0 comments
Owner

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

State: closed
Merged: No


Here is the code I'd like to use:

$tasks = $em
    ->createQuery('SELECT wt FROM Something wt')
    ->setHint(Query::HINT_LOCK_MODE, LockMode::PESSIMISTIC_WRITE)
    ->useResultCache(false)
    ->setHydrationCacheProfile(null)
    ->getResult()
;

Here is the result:

PHP Fatal error:  Call to a member function getResultCacheDriver() on a non-object in /xxx/vendor/doctrine/orm/lib/Doctrine/ORM/AbstractQuery.php on line XXX

Here is the workaround we're using:

class DisabledCache implements Cache
{
    function fetch($id)
    {
        return false;
    }

    function contains($id)
    {
        return false;
    }

    function save($id, $data, $lifeTime = 0)
    {
        return true;
    }

    function delete($id)
    {
        return true;
    }

    function getStats()
    {
        return null;
    }
}

$tasks = $em
    ->createQuery('SELECT wt FROM Something wt')
    ->setHint(Query::HINT_LOCK_MODE, LockMode::PESSIMISTIC_WRITE)
    ->useResultCache(false)
    ->setHydrationCacheProfile(new QueryCacheProfile(0, 'disabled', new DisabledCache))
    ->getResult()
;
**Original Pull Request:** https://github.com/doctrine/orm/pull/5842 **State:** closed **Merged:** No --- Here is the code I'd like to use: ``` php $tasks = $em ->createQuery('SELECT wt FROM Something wt') ->setHint(Query::HINT_LOCK_MODE, LockMode::PESSIMISTIC_WRITE) ->useResultCache(false) ->setHydrationCacheProfile(null) ->getResult() ; ``` Here is the result: ``` PHP Fatal error: Call to a member function getResultCacheDriver() on a non-object in /xxx/vendor/doctrine/orm/lib/Doctrine/ORM/AbstractQuery.php on line XXX ``` Here is the workaround we're using: ``` php class DisabledCache implements Cache { function fetch($id) { return false; } function contains($id) { return false; } function save($id, $data, $lifeTime = 0) { return true; } function delete($id) { return true; } function getStats() { return null; } } $tasks = $em ->createQuery('SELECT wt FROM Something wt') ->setHint(Query::HINT_LOCK_MODE, LockMode::PESSIMISTIC_WRITE) ->useResultCache(false) ->setHydrationCacheProfile(new QueryCacheProfile(0, 'disabled', new DisabledCache)) ->getResult() ; ```
admin added the pull-request label 2026-01-22 16:05:18 +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#9752