开发者

PHP class name from variable with "class not found" check?

开发者 https://www.devze.com 2023-01-24 05:00 出处:网络
I\'m trying to implement the strategy pattern in PHP, creating objects with variable variables as follows:

I'm trying to implement the strategy pattern in PHP, creating objects with variable variables as follows:

$className = 'MyClass';
$myObject = new $className();

Is there a way to verify that $cla开发者_如何转开发ssName exists as a Class?


class_exists($className)

0

精彩评论

暂无评论...
验证码 换一张
取 消