namespace My\Namespace; use ExtNamespace\FloatToInt; class test { function t () { $class_a = 'FloatToInt'; $class_b = 'ExtNamespace\FloatToInt'; // $d = new FloatToInt() - работает. // $d = new $class_a() - не работает: Fatal error: Class 'FloatToInt' not found... // $d = new $class_b() - работает. } }
Tell me how to write the class name to a variable without specifying the full path to the class and why does the creation of an object with new $ class_a () not work? Indeed, at first glance, the code in the second and third lines is identical:
1 $class_a = 'FloatToInt'; 2 $d = new FloatToInt(); 3 $d = new $class_a();