0

Suppose I have three declared classes:

A, B, C

Class A must be instantiated only in class B.

Is there a way to specify in itself that class A should only be instantiated in class B (via constructor for instance) and not in other classes?

Peyman Mohamadpour
  • 17,954
  • 24
  • 89
  • 100
user8555937
  • 2,161
  • 1
  • 14
  • 39
  • See https://stackoverflow.com/questions/2110732/how-to-get-name-of-calling-function-method-in-php for how to get the name of the calling function. The constructor can check if the calling function is in one of those classes. – Barmar Jun 12 '20 at 07:32
  • 1
    https://stackoverflow.com/questions/16424257/nested-or-inner-class-in-php may also be worth a read. – Nigel Ren Jun 12 '20 at 09:10

0 Answers0