Re: switch() and default:

php.internals

Frank M. Kromann

21 years ago
Hi Andi, It might be documented but it has not always been working like this. I have some code that I have not touched for over 2 years, and It has workd with both PHP4 and PHP5 versions (even PHP5-1-0-dev from Aug 19 2004 17:03:39 ). After upgrading to PHP5 CVS-HEAD it stopped working. I have no problem forcing the default: to the buttom, but as the behavior of PHP changd I just wanted to know if it was intentional or a bug. In my case I hace a long æist of case 1, case 2 etc. and the default case was the first so I had that on the top of thie list to keep a nice order. - Frank
> It's always been like that and has been documented for ages in the
manual.
> > Andi > > At 08:24 PM 10/7/2004 -0700, Frank M. Kromann wrote: > >Hello Everyone, > > > >I just discovered a small thing in the switch() statement. The position
of

Unnamed Person

21 years ago
"Frank M. Kromann" <frank@kromann.info> writes:
> It might be documented but it has not always been working like this. I > have some code that I have not touched for over 2 years, and It has workd > with both PHP4 and PHP5 versions (even PHP5-1-0-dev from Aug 19 2004 > 17:03:39 ). After upgrading to PHP5 CVS-HEAD it stopped working.
I haven't updated to HEAD in the past few weeks so I haven't seen the problem, but I too have a number of cases where the default condition is the first in the list. It's been working fine. Although I can reorganize the switch to put the default at the end, that makes the code less readable since the numeric ordering of the cases is then out of order. I'd certainly prefer the C-like BC be retained, allowing default: to be wherever is appropriate in the code. Derrell