php - Multiple time execution bypass -


i have follow (sample) code:

class foo {     public function __construct() {         $this->bar = new bar();         $this->baz = new bazr();     } }  class bar extends foo {     public function __construct() {         parent::__construct();          $baz = $this->baz->alert();     } }  class baz extends foo {     public function __construct() {         parent::__construct();     }      public function alert() {         echo('hello!');     } }  new foo(); 

which generate fatal error: maximum function nesting level of '100' reached, aborting!. want is, this, ofcourse different code , no errors.

what want 1 way know when instance created , not allow more instances of same object, avoiding circular reference.

learned singletom, but, nothing worked. have idea?

the constructor of foo calls constructor of bar calls constructor of foo calls constructor of bar... idea. after 100 times tells it's dizzy. don't create circular reference that.


Comments

Popular posts from this blog

django - How can I change user group without delete record -

java - Need to add SOAP security token -

java - EclipseLink JPA Object is not a known entity type -