2.3. TMultiton

trait TMultiton
{
    use TStaticClass;
}

The TMultiton trait is representing a multiton class that ensures a single instance per key. A possible usage is for caching config files, every config.ini file having its own instance which loads the file only once.

2.3.1. initialize

protected static initialize(TMultiton $instance, $key)
Parameters:
  • $instance – The newly created instance
  • $key – The key of the newly created instance

Initialize is called when a new instance is created. It is used to initialize the state of the object.

2.3.2. instance

public static instance($key)
Parameters:key – The identifying key of the instance

Return the single instance of the class for the passed key that is created only on the first call of this function for a specific key.