"Use" directive when using ReflectionClass in the symfony application
source link: https://www.codesd.com/item/use-directive-when-using-reflectionclass-in-the-symfony-application.html
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
"Use" directive when using ReflectionClass in the symfony application
I have a class in my symfony 3 app with a method that should instantiate a Model class dynamically using the name that's passed in to the function, i.e.:
static function getInstance($modelName){
use $modelName;
$r = new \ReflectionClass($modelName);
return $r->newInstanceArgs();
}
But there's a syntax error on the use
directive.
I've tried adding specific use
statements for every class at the top of the file; and I've also tried using require
with a fully qualified path to the corresponding PHP file - but neither approach has worked.
Please advise how to correctly do this.
What about this? use qualified class name
static function getInstance($modelName){
$r = new \ReflectionClass('AppBundle\Entity\\' . $modelName);
return $r->newInstanceArgs();
}
Related Articles
Using cookies on the iOS application with AFNetworking
Where exactly to use ngCloak in the existing application
Use case for the Web Application API
Can I use Jquery in the Windows application?
Using graphics in the web application (negative value in the bar chart)
Rendering the text of the colored list using HTML in the deployed application
Unable to deploy the symfony application to Heroku
Disabling the symfony application during maintenance
How to do so in Linux, so that when reading a file, the current application receives data from another application?
How to call the method automatically when changing views in the TabBar application with a single ViewController
Runtime configuration for the Symfony application
AccessControlException when using hibernation in the wso2 application cloud
Do not use serialize for the Symfony user role
Is there a way to use ffmpeg in the c # application?
Recommend
About Joyk
Aggregate valuable and interesting links.
Joyk means Joy of geeK