Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
是否存在基于返回的函数字符串创建类的新实例的单线(是的,我喜欢它们)?
$obj = new {functionThatReturnsAStringValue()}();
我明白你想要什么,但我认为你可以这样做:
$obj = ($class = functionThatReturnsAStringValue()) ? new $class() : null;
function getObject() { return 'DateTime'; } $datetime = call_user_func(function ($obj) { return new $obj; }, getObject());