Well, I've often found the need to treat several conditions with the
same set of statements within a switch:
switch($some_number)
{
case 1:
case 2:
{
// do some shizzle
break;
}
case 3:
{
// foshizzle that nizzle
break;
}
default:
{
// dizzle everything else here
}
}
You never need a break in the last case, and you don't need a default
case if you know all the values you expect, although if you do have one,
I believe it does have to be the last statement.
Ash
www.ashleysheridan.co.uk
--- Begin Message ---
At 10:58 AM +0100 9/12/08, Luke wrote:
I wonder if this is a shared trait between C and PHP (since I
understand PHP is written in C) that the break; and the default: are
placed for good practice in all switch statements since they prevent
memory leaks?
First, the evolution of computer languages from rocks to what we have
now has produced numerous logic constructs. Those that are
successful, remain and appear again and again in subsequent
languages. Those that are not successful fade way. As a result, all
languages are converging on a successful set logic constructs.
The CASE statement has been one of those concepts that has been
successful and I expect it to remain -- whereas, others like DO/WHILE
may fade away -- I never found reason to use it.
I may be wrong, I seem to remember that the CASE statement preceded
the ELSE IF statement -- and is one of the reasons why I never use it
(being dyslexic is another). If I was THE PHP czar, I would drop-kick
ELSE IF -- for me it's perfectly useless and confusing. YMMV.
Second, as for memory leaks??? The CASE statement, nor any other
logic configuration, has anything to do with memory leaks -- that's
different.
I am sure there are people who will disagree, but a memory leak is a
condition that comes about from declaring a memory allocation (a
specific size) for a variable and then later upon discarding that
variable and releasing its memory back into the free memory an error
is made in its size.
In other words, memory leaks are accounting errors in memory
allocations that reduces the amount of available free memory OR worse
yet, mistakenly assigns memory to new variables that is still in use
and has not been released -- all of which can crash a program.
Cheers,
tedd
--
-------
http://sperling.com http://ancientstones.com http://earthstones.com
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php
--- End Message ---
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php