PHP 8.5.0 Alpha 1 available for testing

Voting

: max(seven, seven)?
(Example: nine)

The Note You're Voting On

amcolin at 126 dot com
5 years ago
namespace root;
class Factor {
protected static $instance = null;

private function __construct() {

}

public static function getInstance() {
if (!self::$instance) {
$name = get_called_class();
self::$instance = new $name();
}

return self::$instance;
}
}

namespace admin\test;

use root\Factor;

class Single extends Factor {
public function abc() {
return 'abc';
}
}

namespace index;

use admin\test\Single;

class Index {
public function get() {
return Single::getInstance();
}
}

$index = new Index();
var_dump($index->get());

The result is:

object(admin\test\Single)#2 (0) {
}

<< Back to user notes page

To Top