Re: [PHP-DEV] PHP 4.0 Bug #8428 Updated: continue doesn't pass thru a switch statement From: Adam Trachtenberg (adam <email protected>)
Date: 01/08/01

On Mon, 8 Jan 2001, Stanislav Malyshev wrote:

> Consider this syntax borrowed from Perl, not C :) In Perl it behaves in
> quite different way, IIRC.

If it was to operate identical to the Perl behavior, that'd be acceptiable
to me.

> Why is it _incorrect_? Just because C is always correct?

I would argue that C is always correct by definition. It's a shitty
arguement, since it leaves no room for actual debate. However, my claim is
that when you've got an embedded base the size of C, then you're stuck
supporting its behavior even when everyone knows it's wrong and agrees
that it'd be better a different way.

Now, I don't think that means you can't innovate beyond C, but just that
the syntax shouldn't appear to be /like/ C. (Or, for that matter, like
Perl or any other well-established language.) Syntax that identical in
look, but different in behavior, can only lead to problems because people
are bound to make assumptions that it'll act how they've learned it to
act. I think that's natural and part of the reason why PHP's borrowed
language constructs from C and Perl.

If you're going to break from expected behavior, you should break hard.

> BTW, I would always advise against using of evaluation order of _any_
> operator (except probably for logic shortcuts) because it's just not
> readable (and not portable, as you just saw).

Well, of course it's not readable, isn't the whole point of using ?: to
create confusion? :) And, I've never been bitten by that ?: difference,
nor do I think most anyone will. However, my point is that there is an
established evaluation order that most languages observe. PHP's matches
C's operator-for-operator, with this one exception. (Which, from what I
remember, seems to be an honest mistake that nobody caught until it was
too late.) After seeing that == and && and everything else works as they
expect, I would think someone would jump to believing that ?: would be the
same and why wouldn't portability be something worth perserving?

Likewise, we probably wouldn't want to introduce something that looks like
$foo =~ /bar/ that didn't operate like Perl's =~.

In the end, I always use break and never continue in switch()es. However,
it seems like a great place to introduce the possibility of a bug where
one could be avoided.

-adam

-- 
/ adam maccabee trachtenberg | it's what you think... \
\ adam <email protected>           | http://www.student.com /

-- PHP Development Mailing List <http://www.php.net/> To unsubscribe, e-mail: php-dev-unsubscribe <email protected> For additional commands, e-mail: php-dev-help <email protected> To contact the list administrators, e-mail: php-list-admin <email protected>