Doctrine 2 - ORM
  1. Doctrine 2 - ORM
  2. DDC-1698

Inconsistent proxy file name & namespace result in __PHP_Incomplete_Class when unserializing entities

    Details

    • Type: Improvement Improvement
    • Status: Reopened
    • Priority: Major Major
    • Resolution: Unresolved
    • Affects Version/s: 2.2, 2.2.1, 2.3, 2.4
    • Fix Version/s: None
    • Component/s: ORM
    • Security Level: All
    • Labels:

      Description

      Starting with Doctrine 2.2, the Proxy classes have inconsistent naming with their file name, which raises problems with class autoloading.
      For example, a class named Application\Model\User creates the following proxy class:

      Application\Proxy\__CG__\Application\Model\User
      

      This class is located in the following file:

      Application/Proxy/__CG__ApplicationModelUser.php
      

      But whe we serialize such an entity, then unserialize it in another session, the framework autoloader expects the class to be located in:

      Application/Proxy/__CG__/Application/Model/User.php
      

      But it is not.
      As a result, a __PHP_Incomplete_Class is created instead of the expected proxy class.

      I'm not sure whether this is an intended behavior, but I would assume this is a bug.

        Activity

        Hide
        Benjamin Morel added a comment -

        @Benjamin Eberlei
        In 2.3 we still have to manually call Autoloader::register() before unserializing entities that may contain proxies.
        So EntityManager::create() still doesn't register it. Is there a plan to add this feature?

        Show
        Benjamin Morel added a comment - @Benjamin Eberlei In 2.3 we still have to manually call Autoloader::register() before unserializing entities that may contain proxies. So EntityManager::create() still doesn't register it. Is there a plan to add this feature?
        Hide
        Benjamin Eberlei added a comment -

        Benjamin Morel Not at the moment, seems too dangerous for me since it might produce race conditions. This should really be done in the bootstrap of the system.

        We need to document this though.

        Show
        Benjamin Eberlei added a comment - Benjamin Morel Not at the moment, seems too dangerous for me since it might produce race conditions. This should really be done in the bootstrap of the system. We need to document this though.
        Hide
        Benjamin Morel added a comment -

        Ok, thanks for your answer!

        Show
        Benjamin Morel added a comment - Ok, thanks for your answer!
        Hide
        Matthieu Napoli added a comment -

        Sorry to be a pain, but can the description of the task be updated:

        • Affects Version/s: should show all versions (or none) but not just 2.2, 2.2.1
        • Fix Version/s: should be blank

        This is to make it clear that this bug is not resolved (since we are way past v2.2.2).

        Thanks

        Show
        Matthieu Napoli added a comment - Sorry to be a pain, but can the description of the task be updated: Affects Version/s: should show all versions (or none) but not just 2.2, 2.2.1 Fix Version/s: should be blank This is to make it clear that this bug is not resolved (since we are way past v2.2.2). Thanks
        Hide
        Chris Hawkins added a comment - - edited

        Some additional documentation about this would be useful. I just spent some considerable time diagnosing an error related to restoring an entity from a cache. I wasn't able to find a mention of the need to call Autoloader::register until I found this page. It was resolved fairly quickly after I found this. For reference, I added this to my bootstrap:

        ini_set('unserialize_callback_func', 'proxymissing');
        function proxymissing( $name ) {
        	if ( preg_match( '/^DoctrineProxies/', $name ) ) {
        		\Doctrine\ORM\Proxy\Autoloader::register( PROXYPATH, 'DoctrineProxies' );
        	}
        }
        
        Show
        Chris Hawkins added a comment - - edited Some additional documentation about this would be useful. I just spent some considerable time diagnosing an error related to restoring an entity from a cache. I wasn't able to find a mention of the need to call Autoloader::register until I found this page. It was resolved fairly quickly after I found this. For reference, I added this to my bootstrap: ini_set('unserialize_callback_func', 'proxymissing'); function proxymissing( $name ) { if ( preg_match( '/^DoctrineProxies/', $name ) ) { \Doctrine\ORM\Proxy\Autoloader::register( PROXYPATH, 'DoctrineProxies' ); } }

          People

          • Assignee:
            Marco Pivetta
            Reporter:
            Benjamin Morel
          • Votes:
            1 Vote for this issue
            Watchers:
            5 Start watching this issue

            Dates

            • Created:
              Updated: