Hi!

> First, E_NOTICE exists to permit a compromise between people like Zeev 
> that think its introduction was an error and that one should be able to 
> refer to undefined variables and people who prefer a stricter model. For 
> the programmers that follow this stricter model, an E_NOTICE ends ups 
> frequently being a fatal (because, for instance, you invoke a method on 
> the resulting null); some other times you're lucky and you just missed 
> an "else $var = null" branch, other times the error is far more serious, 
> like an unintended null -> 0 conversion.

So it basically comes to "it doesn't follow but E_NOTICE in fact should
be fatal for those who prefer a stricter model because I had some code
where it indicated a bug". That's exactly what I was talking about. But
PHP is not designed to be this way and PHP code is not written this way,
for better or for worse. If you want to start a radical transformation
of PHP into something like Python where accessing a value in array that
doesn't exist (and pretty much any other unexpected thing) throws an
exception that finishes your application (or at least a segment of it
inside a catch-all-then-bail-out exception wrapper) - it should not be
done in a hush-hush case-by-case basis. It should be announced upfront
and consensus should be obtained. I personally do not see such
transformation as beneficial, and I suspect many others do not either.
But in any case this would not work on case-by-case basis.

If however we want to keep the current nature of PHP, introducing fatal
errors where it can be avoided only because it _may be_ a bug makes
little sense - we have tons of situations where it may be a bug - just
as you described with E_NOTICE and no fatal error there. We use fatal
error only when there's no logical exit from the situation - like you
tell to call a function and it doesn't exist - there's no default we
could substitute and there's no logical way to react on it. When we
access undefined variable though there is such way - we can assume the
variable is empty. We do the same with foreach() - if it's not iterable,
we assume no iteration happens. Can it be a bug? Sure it can. Do we
produce fatal error in this case? No we do not. Why we should start
doing it with generators? Just because they use iterator classes as
implementation detail? Doesn't make too much sense to me.
-- 
Stanislav Malyshev, Software Architect
SugarCRM: http://www.sugarcrm.com/
(408)454-6900 ext. 227

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

Reply via email to