Sebastian Bergmann wrote:
 The Reflection API was introduced at the same time as exceptions. It
 therefore makes perfect sense to make consistent use of exception in
 the Reflection API.

You don't have to treat everything like a nail just because you have a hammer.


 So the people who know how to do it right should do without because of
 the people who do not know how to it right? This is absurd.

There is more than One Single True Way of doing things. Exceptions are not the silver bullet of programming.


 Because

   try {
       $class  = new ReflectionClass($this);
       $method = $class->getMethod($this->name);
   }

   catch (ReflectionException $e) {
       $this->fail($e->getMessage());
   }

is clearer than

[ overly complicated version removed ]

Your example above to me would be equivalent to

$class = new ReflectionClass($this);

if ($method = $class->getMethod($this->name))
{
}
else
        $this->fail("Method $this->name does not exist");

which I find as readable. And for more complicated stuff the exception-based version get's quickly uglier too (e.g. multiple try...catch blocks). [Don't try to nit-pick, I'll simple ignore it because I consider our examples to be of academic nature :-)]

Now whenever there are multiple ways of doing things I prefer to choose a simple, light-weight solution. You happen to like exceptions. All I ask is that you (and everybody working on PHP) stop for a second and consider other options when you make people use exceptions in a standard PHP interface.

I realize that the decision to go OO+exceptions for Reflection has already been made a while ago and I think we can therefore end the discussion here, the compromise to have hasMethod() has been reached earlier on already anyway :-)

- Chris

--
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: http://www.php.net/unsub.php



Reply via email to