tags:

views:

10

answers:

0

When Doctrine hydrates Records, it does so in a way that all instances to a record are the same. Here's an example:

$p = ProfileTable::getInstance()->findOneBy('id', 5);
$q = ProfileTable::getInstance()->findOneBy('id', 5);
echo 'P before: ' . $p->name . "\n";
echo 'Q before: ' . $q->name . "\n";
$p->name = 'Sam';
echo 'P after: ' . $p->name . "\n";
echo 'Q after: ' . $q->name . "\n";

Output:

P before: John
Q before: John
P after: Sam
Q after: Sam

It turns out that $p and $q actually reference the same thing, that is, $p === $q.

I'm relatively familiar with Doctrine's internals and I don't understand how/where this is happening. Is Doctrine maintaining a reference of all queried objects somewhere?