开发者

Selecting class using strings

开发者 https://www.devze.com 2023-02-13 12:01 出处:网络
I want to write an extension system for my CMS. I want the extensions to be installed by copying a folder into the extensions folder. The content of the extension is a class with the same name as the

I want to write an extension system for my CMS. I want the extensions to be installed by copying a folder into the extensions folder. The content of the extension is a class with the same name as the name of the folder. So my CM开发者_如何学GoS can list the extensions by the names of the folders in the extension folder. The problem is that I can't find a way to select the class even though I have a string containing it's name.

So to sum up, is there any way to create an instance of a class or calling static functions of a class, by referring to said class using a string with the class name?

I hope you understand what I mean and thanks for any help


You mean like so?

$classname = "myClass";

$object = new $classname();
0

精彩评论

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

关注公众号