Reputation: 354
How to implement this:
<?php
class MyClass1
{
public function __construct(MyClass2 $objClass2)
{
$this->objClass2 = $objClass2;
}
}
class MyClass2
{
public function setClass1(MyClass1 $objClass1)
{
$this->objClass1 = $objClass1;
}
}
?>
I mean I need to create a MyClass2
object, put it into MyClass1
constructor and then I need MyClass1
object to be put into MyClass2
object that was created before via setClass1 method. Is it possible to do in DI config in ZendFramework?
Upvotes: 3
Views: 257
Reputation: 17166
You don't want this! If you injected Class2 into Class1 you already have access to it, by using $class1->class2->somethingSomething();
, or you can retrieve it by $class->getClass2();
and so on... I don't know what your actual scenario is, but when you have cyclic dependecy, something's gone awry.
Upvotes: 3