8000 minor #19689 [DI] Cleanup array_key_exists (ro0NL) · symfony/symfony@c89f80a · GitHub
[go: up one dir, main page]

Skip to content

Commit c89f80a

Browse files
committed
minor #19689 [DI] Cleanup array_key_exists (ro0NL)
This PR was squashed before being merged into the 2.7 branch (closes #19689). Discussion ---------- [DI] Cleanup array_key_exists | Q | A | ------------- | --- | Branch? | 2.7 | Bug fix? | no | New feature? | no | BC breaks? | no | Deprecations? | no | Tests pass? | yes | Fixed tickets | comma-separated list of tickets fixed by the PR, if any | License | MIT | Doc PR | reference to the documentation PR, if any Investigated this a bit, and to me it looks like left-over code. `null` doesnt end up in `$this->services` by design (this was done in #8582) so it seems. The test added then for regression still passes :) I cant believe we guarantee BC for users doing `$this->services['id'] = null` (due protected), allowing them to break the design of `has`, `get` and `initialized` right now. This also happens for `$this->definitions` in `ContainerBuilder`, maybe because `Container` did it alteady.. but im not sure. Then again, there's this comment: #14470 (comment) Commits ------- 3306c70 [DI] Cleanup array_key_exists
2 parents 386e5e7 + 3306c70 commit c89f80a

File tree

2 files changed

+5
-6
lines changed

2 files changed

+5
-6
lines changed

src/Symfony/Component/DependencyInjection/Container.php

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -223,7 +223,6 @@ public function has($id)
223223
if ('service_container' === $id
224224
|| isset($this->aliases[$id])
225225
|| isset($this->services[$id])
226-
|| array_key_exists($id, $this->services)
227226
) {
228227
return true;
229228
}
@@ -266,7 +265,7 @@ public function get($id, $invalidBehavior = self::EXCEPTION_ON_INVALID_REFERENCE
266265
$id = $this->aliases[$id];
267266
}
268267
// Re-use shared service instance if it exists.
269-
if (isset($this->services[$id]) || array_key_exists($id, $this->services)) {
268+
if (isset($this->services[$id])) {
270269
return $this->services[$id];
271270
}
272271

@@ -348,7 +347,7 @@ public function initialized($id)
348347
$id = $this->aliases[$id];
349348
}
350349

351-
return isset($this->services[$id]) || array_key_exists($id, $this->services);
350+
return isset($this->services[$id]);
352351
}
353352

354353
/**

src/Symfony/Component/DependencyInjection/ContainerBuilder.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -436,7 +436,7 @@ public function get($id, $invalidBehavior = ContainerInterface::EXCEPTION_ON_INV
436436
return $service;
437437
}
438438

439-
if (!array_key_exists($id, $this->definitions) && isset($this->aliasDefinitions[$id])) {
439+
if (!isset($this->definitions[$id]) && isset($this->aliasDefinitions[$id])) {
440440
return $this->get($this->aliasDefinitions[$id]);
441441
}
442442

@@ -784,7 +784,7 @@ public function setDefinition($id, Definition $definition)
784784
*/
785785
public function hasDefinition($id)
786786
{
787-
return array_key_exists(strtolower($id), $this->definitions);
787+
return isset($this->definitions[strtolower($id)]);
788788
}
789789

790790
/**
@@ -800,7 +800,7 @@ public function getDefinition($id)
800800
{
801801
$id = strtolower($id);
802802

803-
if (!array_key_exists($id, $this->definitions)) {
803+
if (!isset($this->definitions[$id])) {
804804
throw new ServiceNotFoundException($id);
805805
}
806806

0 commit comments

Comments
 (0)< 30AA /span>
0