On 09/01/2012 04:51 PM, Gustavo Lopes wrote

> * In fact, if there is a unifying theme in the usage of exceptions in
> PHP, is that exceptions are used when OOP interfaces are involved (see
> Zend interfaces, SPL, DateTime and PDO -- though optional there). The
> core vs. non-core argument only looks attractive because there are few
> built-in classes in the core.

I think this is drifting off-topic. Whether or not a generator is an
object is an implementation detail. If I write:

  $things = getStuff();
  foreach($things as $thing) {
    do_some($thing);
  }

which is very normal PHP that you see in millions of lines of code, I
would not expect to have to wrap my foreach in a try/catch here. Even if
I am used to exceptions and might have:

  $things = getStuff();
  foreach($things as $thing) {
    try {
      do_some($thing);
    } catch (Exception $e) {
      echo $e->getMessage();
    }
  }

this is still going to fatal on me eventually with an uncaught exception
on the foreach if, for example, I pass the generator a second time to
something and it has run off the end. This is something you don't have
to worry about currently and I think it will cause headaches for people
when they start passing generators around. In theory I should be able to
pass a generator to any existing code that takes an array without having
to worry about modifying that code to catch foreach exceptions. And yes,
I know it is actually a generator exception, but to the average user it
will look like it is foreach throwing.

-Rasmus

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

Reply via email to