diff --git a/src/Symfony/Components/DependencyInjection/Container.php b/src/Symfony/Components/DependencyInjection/Container.php index 95ec411821..c6a011a218 100644 --- a/src/Symfony/Components/DependencyInjection/Container.php +++ b/src/Symfony/Components/DependencyInjection/Container.php @@ -193,7 +193,7 @@ class Container implements ContainerInterface, \ArrayAccess throw new \InvalidArgumentException(sprintf('A service id should be a string (%s given).', str_replace("\n", '', var_export($id, true)))); } - if (method_exists($this, $method = 'get'.strtr($id, array('_' => '', '.' => '_')).'Service')) + if (method_exists($this, $method = 'get'.strtr($id, array('_' => '', '.' => '_')).'Service') && 'getService' !== $method) { return $this->$method(); } diff --git a/tests/Symfony/Tests/Components/DependencyInjection/ContainerTest.php b/tests/Symfony/Tests/Components/DependencyInjection/ContainerTest.php index 4fb0838e89..ff3baf28f6 100644 --- a/tests/Symfony/Tests/Components/DependencyInjection/ContainerTest.php +++ b/tests/Symfony/Tests/Components/DependencyInjection/ContainerTest.php @@ -176,6 +176,20 @@ class ContainerTest extends \PHPUnit_Framework_TestCase { } } + + public function testGetService() + { + $sc = new Container(); + + try + { + $sc->getService(''); + $this->fail('->getService() throws a \InvalidArgumentException exception if the service is empty'); + } + catch (\InvalidArgumentException $e) + { + } + } } class ProjectServiceContainer extends Container