class U_Pizza_Install
{
protected static $instance = null;
public static function instance()
{
if (is_null(self::$instance)) {
self::$instance = new self();
}
return self::$instance;
}
public function __construct()
{
$this->include();
}
public function include()
{
require_once U_PIZZA_PATH . 'includes/pizza-functions.php';
require_once U_PIZZA_PATH . 'includes/pizza.php';
U_Pizza::instance();
}
}
function init_plugin_pizza()
{
U_Pizza_Install::instance();
}
What is this part doing → U_Pizza_Install::instance();
The class constructor is calling the static method instance(); instance is a static function that checks to see if there exists an object of its type; if so, it self-references. If not, it creates a new instance of itself and returns it.
It’s known as the Singleton Pattern that ensures there will only be ever one instance of the U_Pizza_Install class, not multiple.
It used to be quite popular but its now considered an anti-pattern, as Dependency Injection should be used instead.
In this specific case the class only includes some files, which shouldn’t be done in a class at all, but either in a function or (preferred) through composer.