PHP Using a variable when calling a static method

后端 未结 5 613
故里飘歌
故里飘歌 2021-01-14 01:55

I have three classes that all have a static function called \'create\'. I would like to call the appropriate function dynamically based on the output from a form, but am hav

5条回答
  •  说谎
    说谎 (楼主)
    2021-01-14 02:31

    I may be misunderstanding what you want, but how about this?

    switch ($_POST['ClassType']) {
        case "Class1":
            $class1::create();
            break;
        case "Class2":
            $class2::create();
            break;
        // etc.
    }
    

    If that doesn't work, you should look into EVAL (dangerous, be careful.)

提交回复
热议问题