php - Use variable's string into class names or other -
i want use variables inside class names.
for example, let's set variable named $var "index2". want print index2 inside class name this:
controller_index2, instead of doing manually, can print var name there this:
controller_$var;   but assume that's syntax error.
how can this?
    function __construct()     {         $this->_section = self::path();          new controller_{$this->_section};      }      
it's hideous hack, but:
php > class foo { function x_1() { echo 'success'; } }; php > $x = new foo; php > $one = 1; php > $x->{"x_$one"}();           ^^^^^^^^^^^^ success   instead of trying build method name on-the-fly string, array of methods may more suitable. use variables array's key.
Comments
Post a Comment