Details
-
Type:
Bug
-
Status:
Resolved
-
Priority:
Major
-
Resolution: Invalid
-
Affects Version/s: 2.1.3, 2.1.4, 2.1.5, 2.1.6, 2.2-BETA1, 2.2-BETA2, 2.2.0-RC1, 2.2, 2.2.1, Git Master
-
Fix Version/s: None
-
Component/s: ORM
-
Security Level: All
-
Labels:None
Description
Bug was introduced in commit https://github.com/doctrine/doctrine2/commit/619a31913a4f5952248a0b909a25c2020619c29f (Message "DDC-1517 - Fix EntityRepository#find() and EntityManager#getReference...").
If a variable with null value is passed to a repository find() method the exception is thrown because isset() is used instead of array_key_exists() to check for a valid identifier key (and isset returns false when the variable has null). This introduces a BC break in current scenarios that expected that doing a find($variableWithNullValue) should return null instead of raising an exception.
lib/Doctrine/ORM/EntityRepository.php Line 113
$sortedId = array();
foreach ($this->_class->identifier as $identifier) {
if (!isset($id[$identifier])) {
throw ORMException::missingIdentifierField($this->_class->name, $identifier);
}
$sortedId[$identifier] = $id[$identifier];
}
Should be:
lib/Doctrine/ORM/EntityRepository.php Line 113
$sortedId = array();
foreach ($this->_class->identifier as $identifier) {
if ( ! array_key_exists($identifier, $id) ) {
throw ORMException::missingIdentifierField($this->_class->name, $identifier);
}
$sortedId[$identifier] = $id[$identifier];
}
Patch attached