overhead of using Reflection?

Giganews Newsgroups
Subject: overhead of using Reflection?
Posted by:  Alex Weber (alexweber…@gmail.com)
Date: Sat, 19 Sep 2009

I have the following code:

            $rc = new ReflectionClass($this->getController());
            if($rc->implementsInterface('IController')){
                if($rc->hasMethod($this->getAction())){
                    $controller = $rc->newInstance();
                    $method = $rc->getMethod($this->getAction());
                    $method->invoke($controller);
                }else{
                    throw new Exception('Action not found');
                }
            }else{
                throw new Exception('Controller found but doesnt
implement interface');
            }

despite working as expected, the exact same functionality could be
achieved using class_implements(), get_class_methods() and
call_user_func()...

Clearly there is no need to instantiate Reflection classes and I only
did it this way because its more elegant, but I'm wondering whether
the overhead of the Reflection-based approach is worth it at all?

Replies