Is it bad to use Reflection in production code?

ditaritty

New Member
I've got a \[code\]Validator\[/code\] class which creates an instance of a \[code\]Validations\[/code\] class, which contains all the validation methods. When a validation is performed, \[code\]__call\[/code\] in \[code\]Validator\[/code\] is used to dispatch a call \[code\]Validator->validate_method\[/code\] to \[code\]Validations->method\[/code\].So for instance, there is a method in \[code\]Validations\[/code\] called \[code\]length_of\[/code\]. When the following code is run:\[code\]$v = new Validator();$v->validate_length_of(...);\[/code\]the \[code\]length_of\[/code\] validation in the \[code\]Validations\[/code\] class is executed.In order to ensure that \[code\]__call\[/code\] doesn't try to dispatch to an invalid or non-public \[code\]Validation\[/code\] method, I use \[code\]ReflectionMethod\[/code\] to check the specified method:\[code\]$method = new ReflectionMethod($this->validations, $validation_method);if (!$method->isPublic()){ // error}\[/code\]I'm pretty sure this is the only way to determine whether or not a method is public, but I'm not sure if Reflection is appropriate to have in production code. Is this a code smell?
 
Back
Top