dynamic class names in php

前端 未结 7 1637
-上瘾入骨i
-上瘾入骨i 2020-12-07 00:31

I have a base class called field and classes that extend this class such as text, select, radio, checkbox, <

7条回答
  •  感情败类
    2020-12-07 00:51

    This should be enough:

    $field_type = 'checkbox';
    $field = new $field_type();
    

    Code I tested it with in PHP 5.3

    $c = 'stdClass';
    
    $a = new $c();
    
    var_dump($a);
    
    >> object(stdClass)#1 (0) {
    }
    

提交回复
热议问题