Skip to content

Commit 85c8451

Browse files
committed
[DependencyInjection] Forbid container cloning
1 parent 0e5eb6b commit 85c8451

File tree

2 files changed

+15
-0
lines changed

2 files changed

+15
-0
lines changed

src/Symfony/Component/DependencyInjection/Container.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,11 @@ public function __construct(ParameterBagInterface $parameterBag = null)
9090
$this->parameterBag = $parameterBag ?: new ParameterBag();
9191
}
9292

93+
public function __clone()
94+
{
95+
throw new \LogicException('Cloning the container is not supported.');
96+
}
97+
9398
/**
9499
* Compiles the container.
95100
*

src/Symfony/Component/DependencyInjection/Tests/ContainerTest.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -662,6 +662,16 @@ public function testAlias()
662662
$this->assertTrue($c->has('alias'));
663663
$this->assertSame($c->get('alias'), $c->get('bar'));
664664
}
665+
666+
/**
667+
* @expectedException LogicException
668+
*/
669+
public function testThatCloningIsNotSupported()
670+
{
671+
$c = new Container();
672+
673+
clone $c;
674+
}
665675
}
666676

667677
class ProjectServiceContainer extends Container

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy