I've got a Validator
class which creates an instance of a Validations
class, which contains all the validation methods. When a validation is performed, __call
in Validator
is used to dispatch a call Validator->validate_method
to Validations->method
.
So for instance, there is a method in Validations
called length_of
. When the following code is run:
$v = new Validator();
$v->validate_length_of(...);
the length_of
validation in the Validations
class is executed.
In order to ensure that __call
doesn't try to dispatch to an invalid or non-public Validation
method, I use ReflectionMethod
to check the specified method:
$method = new ReflectionMethod($this->validations, $validation_method);
if (!$method->isPublic())
{
// error
}
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?