DDC-578: Entity proxy classes don't respect reference returning #710

Closed
opened 2026-01-22 12:47:40 +01:00 by admin · 3 comments
Owner

Originally created by @doctrinebot on GitHub (May 7, 2010).

Jira issue originally created by user jantichy:

Hello, I have entity class containing a method that returns reference:

public class &foo() { ... }

But when Doctrine creates it's proxy class, the reference ampersand in the proxy class disappears:

public class foo() { ... }

It causes incompatibility of the proxy class and unexpected behaviour of the method.

Solution:

Here is the solution, could you please include it to the Doctrine code?

The Doctrine\ORM\Proxy\ProxyFactory should be fixed - in method _generateMethods() there is following line:

$methods .= PHP_EOL . '    public function ' . $method->getName() . '(';

It should be replaced by something like this:

$methods .= PHP_EOL . '    public function ';
if ($method->returnsReference()) {
    $methods .= '&';
}
$methods .= $method->getName() . '(';

Thank you for the fix!

Originally created by @doctrinebot on GitHub (May 7, 2010). Jira issue originally created by user jantichy: Hello, I have entity class containing a method that returns reference: ``` public class &foo() { ... } ``` But when Doctrine creates it's proxy class, the reference ampersand in the proxy class disappears: ``` public class foo() { ... } ``` It causes incompatibility of the proxy class and unexpected behaviour of the method. **Solution:** Here is the solution, could you please include it to the Doctrine code? The Doctrine\ORM\Proxy\ProxyFactory should be fixed - in method _generateMethods() there is following line: ``` $methods .= PHP_EOL . ' public function ' . $method->getName() . '('; ``` It should be replaced by something like this: ``` $methods .= PHP_EOL . ' public function '; if ($method->returnsReference()) { $methods .= '&'; } $methods .= $method->getName() . '('; ``` Thank you for the fix!
admin added the Bug label 2026-01-22 12:47:40 +01:00
admin closed this issue 2026-01-22 12:47:41 +01:00
Author
Owner

@doctrinebot commented on GitHub (May 10, 2010):

Comment created by shurakai:

Fixed in http://github.com/Shurakai/doctrine2 & sent pull request. Should be fixed in trunk soon.

Thanks for reporting!

@doctrinebot commented on GitHub (May 10, 2010): Comment created by shurakai: Fixed in http://github.com/Shurakai/doctrine2 & sent pull request. Should be fixed in trunk soon. Thanks for reporting!
Author
Owner

@doctrinebot commented on GitHub (May 11, 2010):

Comment created by romanb:

Note though that since php5 the only remaining usecase for returning by reference I can think of are arrays, and this is a very weird thing to do.

@doctrinebot commented on GitHub (May 11, 2010): Comment created by romanb: Note though that since php5 the only remaining usecase for returning by reference I can think of are arrays, and this is a very weird thing to do.
Author
Owner

@doctrinebot commented on GitHub (May 11, 2010):

Issue was closed with resolution "Fixed"

@doctrinebot commented on GitHub (May 11, 2010): 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#710