Home > other >  Is there a method in PHP to use a varible as all or part of a classname?
Is there a method in PHP to use a varible as all or part of a classname?

Time:11-08

Example

$append = 'News';

class My_$append_Component {

}

The goal is to have a dynamic variable which changes the appended string based on folder names found in a directory.

CodePudding user response:

It is possible to use PHP to write a file that contains a class definition and then include or require that file. The newly created class could have a name based on a variable. So I think it's possible although I can't think of any reason you would want to do this.

  •  Tags:  
  • php
  • Related