Skip to content


Improve performance of if key exists in the array #235

merged 1 commit into from

5 participants



thank you for positing this Pull Request. I have automatically opened an issue on our Jira Bug Tracker for you with the details of this Pull-Request. See the Link:

@guilhermeblanco guilhermeblanco merged commit a890fe1 into doctrine:master

1 check passed

Details default The Travis build passed

IMHO, the better way is to reuse here containsKey method:

if ($this->containsKey($key)) { ... }

@basico, why you want to check with the isset first - performance reasons?

Doctrine member

Would be much more overhead

Yes, I add two links related about that in the pull request #235

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Dec 17, 2012
Showing with 2 additions and 2 deletions.
  1. +2 −2 lib/Doctrine/Common/Collections/ArrayCollection.php
4 lib/Doctrine/Common/Collections/ArrayCollection.php
@@ -120,7 +120,7 @@ public function current()
public function remove($key)
- if (array_key_exists($key, $this->_elements)) {
+ if (isset($this->_elements[$key]) || array_key_exists($key, $this->_elements)) {
$removed = $this->_elements[$key];
@@ -214,7 +214,7 @@ public function offsetUnset($offset)
public function containsKey($key)
- return array_key_exists($key, $this->_elements);
+ return isset($this->_elements[$key]) || array_key_exists($key, $this->_elements);
Something went wrong with that request. Please try again.