You can use a Factory Pattern (https://en.wikipedia.org/wiki/Factory_method_pattern) (or something close to that)
<?php
class UserFactory {
static function createUser($username) {
if($username == 'something') {
return new User();
} else {
return null;
}
}
}
class User {}
$user1 = UserFactory::createUser('something');
$user2 = UserFactory::createUser('somethingElse');
var_dump($user1,$user2);
output
object(User)#1 (0) {}
NULL
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…