Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Avoid array_key_exists if isset does the job

By using isset() and relying on short-circuit evaluation
we can avoid a slower array_key_exists() function call, only
needed rarely (when NULL values are stored in the container - issue #40).
  • Loading branch information...
commit da888083759991b9229c5ac1933a82a177161880 1 parent 86cae5c
@spantaleev authored
Showing with 4 additions and 4 deletions.
  1. +4 −4 lib/Pimple.php
View
8 lib/Pimple.php
@@ -74,7 +74,7 @@ function offsetSet($id, $value)
*/
function offsetGet($id)
{
- if (!array_key_exists($id, $this->values)) {
+ if (!isset($this->values[$id]) && !array_key_exists($id, $this->values)) {
throw new InvalidArgumentException(sprintf('Identifier "%s" is not defined.', $id));
}
@@ -90,7 +90,7 @@ function offsetGet($id)
*/
function offsetExists($id)
{
- return array_key_exists($id, $this->values);
+ return isset($this->values[$id]) || array_key_exists($id, $this->values);
}
/**
@@ -151,7 +151,7 @@ function protect(Closure $callable)
*/
function raw($id)
{
- if (!array_key_exists($id, $this->values)) {
+ if (!isset($this->values[$id]) && !array_key_exists($id, $this->values)) {
throw new InvalidArgumentException(sprintf('Identifier "%s" is not defined.', $id));
}
@@ -173,7 +173,7 @@ function raw($id)
*/
function extend($id, Closure $callable)
{
- if (!array_key_exists($id, $this->values)) {
+ if (!isset($this->values[$id]) && !array_key_exists($id, $this->values)) {
throw new InvalidArgumentException(sprintf('Identifier "%s" is not defined.', $id));
}
Please sign in to comment.
Something went wrong with that request. Please try again.