3v4l.org

run code in 500+ PHP versions simultaneously
<?php declare(strict_types=1); error_reporting(-1); ini_set('display_errors', 'On'); class BaseModel { protected static $singleton; public static function __getInstance(): self { if (static::$singleton === null) { static::$singleton = __CLASS__; static::$singleton = new static::$singleton(); } return static::$singleton; } } class AModel extends BaseModel { protected static $singleton; /** ... */ } class BModel extends BaseModel { protected static $singleton; /** ... */ } echo get_class(AModel::__getInstance()), "\n"; echo get_class(BModel::__getInstance());

preferences:
43.5 ms | 1472 KiB | 5 Q