StaticClass

Phuture\Coherence\Support\StaticClass

abstract class StaticClass

Static base class that prevents instantiation and enforces static-only usage.

This class is designed to be extended by classes that should only contain static methods and never be instantiated.

Important: Use static classes sparingly and only when strictly necessary (e.g., utility/helper functions). Static methods can make code harder to test and maintain due to:

  • Inability to mock in unit tests
  • Hidden dependencies and tight coupling
  • Lack of polymorphism and interface implementation

Consider using regular classes with dependency injection for better testability and flexibility. Reserve static classes for simple utility functions that have no state or dependencies.

Example:

 1namespace Phuture\Coherence;
 2
 3use Phuture\Coherence\Class\StaticClass;
 4
 5class StringHelper extends StaticClass
 6{
 7    public static function slugify(string $text): string { ... }
 8}
 9
10$slug = StringHelper::slugify('Hello World');

Methods

__construct()

private function __construct()

Class is static and cannot be instantiated.

__callStatic()

public static function __callStatic(string $name, array $arguments): void

Handle calls to undefined static methods.

Parameter Type Description
$name string The name of the method being called
$arguments array Enumerated array containing the parameters passed to the method

Throws

  • MemberAccessException — If the called static method does not exist on the class