# table-builder-block/2.2.13/includes/Traits/Singleton.php

TableKit – WordPress Table Builder for Data Tables, WooCommerce Product Tables &amp; Post Tables, version 2.2.13. 37 lines.

- Page: https://pluginprobe.com/plugins/table-builder-block/2.2.13/code/includes/Traits/Singleton.php
- Raw: https://pluginprobe.com/plugins/table-builder-block/2.2.13/raw/includes/Traits/Singleton.php
- Modified: 2026-07-28T12:10:42+00:00

Line numbers below start at 1. Link to a line or a range by appending a fragment to the
page URL, for example `https://pluginprobe.com/plugins/table-builder-block/2.2.13/code/includes/Traits/Singleton.php#L10-L20`.

```php
<?php
/**
 * Generic singleton trait for per-class shared instances
 *
 * @package TableKit
 */

namespace TableBuilder\Traits;

/**
 * Generic singleton trait: gives any class a shared instance() accessor
 * keyed by class name, so subclasses don't each need to reimplement it.
 *
 * @package TableBuilder\Traits
 */
trait Singleton {
	/**
	 * Shared instances, keyed by class name.
	 *
	 * @var array
	 */
	private static $instances = array();

	/**
	 * Gets (and lazily creates) the shared instance of the using class.
	 *
	 * @return static The shared instance.
	 */
	public static function instance() {
		$class = get_called_class();
		if ( ! isset( self::$instances[ $class ] ) ) {
			self::$instances[ $class ] = new $class();
		}
		return self::$instances[ $class ];
	}
}

```
