Doctrine 2: Deprecation annotation gives a broken suggestion of what to change #7315

Closed
opened 2026-01-22 15:49:50 +01:00 by admin · 0 comments
Owner

Originally created by @rrehbein on GitHub (Feb 9, 2024).

Bug Report

Q A
BC Break no?
Version 2.18.0

Summary

Following the suggestion in the deprecation notice about which class name to use for 'catch' does not actually work.

Current behavior

Changing catches to Doctrine\ORM\Exception\ORMException per the deprecation notice causes the catches to be ignored.

How to reproduce

<?php

require 'vendor/autoload.php';

try {
    throw \Doctrine\ORM\Exception\ORMException::namedQueryNotFound('demo');
} catch (\Doctrine\ORM\Exception\ORMException $ex) {
    // This is what we are told to change to based on:
    // Note in: src/ORMException.php
    // @deprecated Use Doctrine\ORM\Exception\ORMException for catch and instanceof
    echo "The suggested catch caught\n";
}

Expected behavior

output: The suggested catch caught

Actual behavior

Fatal error: Uncaught Doctrine\ORM\ORMException: Could not find a named query by the name "demo" in /tmp/d/vendor/doctrine/orm/src/ORMException.php:42
Stack trace:
#0 Standard input code(6): Doctrine\ORM\ORMException::namedQueryNotFound()
#1 {main}
  thrown in /tmp/d/vendor/doctrine/orm/src/ORMException.php on line 42
Originally created by @rrehbein on GitHub (Feb 9, 2024). ### Bug Report | Q | A |------------ | ------ | BC Break | no? | Version | 2.18.0 #### Summary Following the suggestion in the deprecation notice about which class name to use for 'catch' does not actually work. #### Current behavior Changing catches to `Doctrine\ORM\Exception\ORMException` per the deprecation notice causes the catches to be ignored. #### How to reproduce ```php <?php require 'vendor/autoload.php'; try { throw \Doctrine\ORM\Exception\ORMException::namedQueryNotFound('demo'); } catch (\Doctrine\ORM\Exception\ORMException $ex) { // This is what we are told to change to based on: // Note in: src/ORMException.php // @deprecated Use Doctrine\ORM\Exception\ORMException for catch and instanceof echo "The suggested catch caught\n"; } ``` #### Expected behavior output: `The suggested catch caught` #### Actual behavior ``` Fatal error: Uncaught Doctrine\ORM\ORMException: Could not find a named query by the name "demo" in /tmp/d/vendor/doctrine/orm/src/ORMException.php:42 Stack trace: #0 Standard input code(6): Doctrine\ORM\ORMException::namedQueryNotFound() #1 {main} thrown in /tmp/d/vendor/doctrine/orm/src/ORMException.php on line 42 ```
admin closed this issue 2026-01-22 15:49:51 +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#7315