Heh, we face a true problem here, and it's deeper than just "should
generators throw exception or not".

Adding Derick's notice, -which is true- it becomes "should Core
features start throwing Exception knowing we've been fighting to
prevent that for years ?".
Generator use objects, right ; but as core features using a core
syntax keyword, one might not expect that to throw an Exception, I so
agree here with Derick idea, at least : with the things as they are
nowadays.

We already have a topic about new error handling into ML , and I think
we really really *should* start agreeing (RFC, patches and votes)
about a new "error" handling process inside PHP, as more and more
features we'll add to the language may be somehow object oriented in
the future.

If the new internal error management we'll debate and agree with is
going to break BC (which, IMO, will), then we should merge it to our
next major (6.0 ?)

And what about SPL ? Which really should join Core features as well,
it has nothing to do into an extension anymore :-P

Julien.Pauli

On Fri, Aug 31, 2012 at 2:36 AM, Morgan L. Owens <pack...@nznet.gen.nz> wrote:
> On 2012-08-30 20:39, Derick Rethans wrote:
>>
>> On Wed, 29 Aug 2012, Gustavo Lopes wrote:
>>
>>> On Wed, 29 Aug 2012 22:10:52 +0200, Derick Rethans <der...@php.net>
>>> wrote:
>>>
>>>>
>>>> Nothing in the core throws an exception, why would this?!
>>>
>>>
>>> This is not accurate. All the iterators throw exceptions on similar
>>> situations. Generators are iterators, so I see no deviation from the
>>> norm here.
>>
>>
>> Nothing shows that they are. In any example I saw, I don't even see any
>> OO syntax/functionality. For me, "yield" is a core syntax *keyword*, and
>> hence: no exceptions.
>>
>> cheers,
>> Derick
>>
> I'm generally of the same opinion as you - issue a warning and skip the
> second loop - but for the fact that the "idiomatic" use
>
> <?php
> foreach(generator() as $k => $item)
> {
>     ...
> }
> ?>
>
> is equivalent to the more explicit "manual" use
>
> <?php
> $generator = generator();
> $generator->rewind();
> while($generator->valid())
> {
>     $k = $generator->key();
>     $item = $generator->current();
>     ...
>     $generator->next();
> }
> ?>
>
> Since explicit control of generators can be useful, they won't necessarily
> be wrapped in the foreach() idiom; would not exceptions be the expected
> behaviour then?
>
> There might be a compromise - trigger a warning in idiomatic use, an
> exception in manual use - but that leaves a nasty taste in the mouth and
> would just cause more problems later.
>
>
>
> --
> PHP Internals - PHP Runtime Development Mailing List
> To unsubscribe, visit: http://www.php.net/unsub.php
>

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

Reply via email to