Ad
Code
Diff
  • function a(){
      // We shall remove the following solution when publish as KATA
      static $poi = null;
      if ($poi) return $poi->create();
      $poi = new class {
         public function create() {
            return new static();
         }
      };
      return $poi->create();
    }
    • function a(){
    • // We shall remove the following solution when publish as KATA
    • static $poi = null;
    • if ($poi) return $poi->create();
    • $poi = new class {
    • public function create() {
    • return new static();
    • }
    • };
    • return $poi->create();
    • }

This is a solution of creating multiple instance from the same anoynoumous class.

Code
Diff
  • function a(){
      static $poi = null;
      if ($poi) return $poi->create();
      $poi = new class {
         public function create() {
            return new static();
         }
      };
      return $poi->create();
    }
    • function a(){return new class {};}
    • $twin1 = a();
    • $twin2 = a();
    • function a(){
    • static $poi = null;
    • if ($poi) return $poi->create();
    • $poi = new class {
    • public function create() {
    • return new static();
    • }
    • };
    • return $poi->create();
    • }