Creating a class name from a variable

I would like to define a class name using variables in PHP. Is it possible?

Let me explain.

I am a small custom CMS that allows the end user to configure a prefix for table names. In this way, the user can define a prefix such as "rc_". The problem is that I have many models that use the table name as a class. For example, if one of my tables rc_posts, the model will be called

class MyModel_Rc_posts extends MyModelController {
         // code here
}

Is there a way to define a class using variables in PHP WITHOUT use eval(), for example:

class MyModel_{$PREFIX}posts extends MyModelController {
// code here
}

The reason I want to avoid eval is because some of these classes can be quite long. Suggestions appreciated.

0
1

class_alias - !

: "" , . , , .

Edit

, class_alias() - , , .

OQ:

class MyModel_Rc_posts extends MyModelController {
         // code here
}

eval("class MyModel_{$PREFIX}posts extends MyModel_Rc_posts {};");

- class_alias().

, , get_class() later - , () , . eval()/extends .

+2

All Articles