DDC-1668: bug with reading cached annotations in Annotation driver #2095

Closed
opened 2026-01-22 13:40:32 +01:00 by admin · 2 comments
Owner

Originally created by @doctrinebot on GitHub (Feb 28, 2012).

Originally assigned to: @beberlei on GitHub.

Jira issue originally created by user vigor_bg:

I had a problem with Class Table Inheritance on first call of a child entity it was working but if call another child in another instance it was not joining with the parent class. After some debugging i found the problem it was not detecting the annotation that is a parent entity to be joined in Doctrine\ORM\Mapping\Driver\AnnotationDriver when the function on line 479 isTransient($className) is called. So after more debugging i found the problem it is in

is_int(key($classAnnotations))

Looks like that after it is cached in and then the cache is read when it returns the array of annotations for the entity class the keys are returned as strings not as integer and if the key is '0' the the value that is_int returns is NULL so the check

 if ($classAnnotations && is_int(key($classAnnotations))) 

fails and it does not foreach the the array of annotations.
Also i found that you are making that check in a couple of places so I maid a quick fix for my self in the Doctrine\Common\Annotations\CachedReader which is if annotations are found that are cached before returning them i call array_values

// Attempt to grab data from cache
        if (($data = $this->cache->fetch($cacheKey)) !== false) {
            if (!$this->debug || $this->isCacheFresh($cacheKey, $class)) {
                return array_values($data);
            }
        }

I am using APC cache.

Originally created by @doctrinebot on GitHub (Feb 28, 2012). Originally assigned to: @beberlei on GitHub. Jira issue originally created by user vigor_bg: I had a problem with Class Table Inheritance on first call of a child entity it was working but if call another child in another instance it was not joining with the parent class. After some debugging i found the problem it was not detecting the annotation that is a parent entity to be joined in Doctrine\ORM\Mapping\Driver\AnnotationDriver when the function on line 479 isTransient($className) is called. So after more debugging i found the problem it is in ``` is_int(key($classAnnotations)) ``` Looks like that after it is cached in and then the cache is read when it returns the array of annotations for the entity class the keys are returned as strings not as integer and if the key is '0' the the value that is_int returns is NULL so the check ``` if ($classAnnotations && is_int(key($classAnnotations))) ``` fails and it does not foreach the the array of annotations. Also i found that you are making that check in a couple of places so I maid a quick fix for my self in the Doctrine\Common\Annotations\CachedReader which is if annotations are found that are cached before returning them i call array_values ``` // Attempt to grab data from cache if (($data = $this->cache->fetch($cacheKey)) !== false) { if (!$this->debug || $this->isCacheFresh($cacheKey, $class)) { return array_values($data); } } ``` I am using APC cache.
admin added the Bug label 2026-01-22 13:40:32 +01:00
admin closed this issue 2026-01-22 13:40:33 +01:00
Author
Owner

@doctrinebot commented on GitHub (Mar 3, 2012):

Comment created by @beberlei:

Fixed

@doctrinebot commented on GitHub (Mar 3, 2012): Comment created by @beberlei: Fixed
Author
Owner

@doctrinebot commented on GitHub (Mar 3, 2012):

Issue was closed with resolution "Fixed"

@doctrinebot commented on GitHub (Mar 3, 2012): Issue was closed with resolution "Fixed"
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: doctrine/archived-orm#2095