At 4:16 PM +0100 1/30/09, Jochem Maas wrote:
tedd schreef:
At 4:43 PM -0500 1/29/09, Frank Stanovcak wrote:
>"
yes...that is legal. as long as the statment resolves to a boolean it
will
work. It's not technically correct, but it does work.
There you go again. What's technically correct?
hiya tedd,
you mean to ask "not technically correct" ... I plead
that it's his statement that is not technically correct.
1. php does a soft comparison ('==' rather than '===') so the
results of each case expression is auto-cast to a boolean
(in the case of switch'ing on TRUE), ergo there is no 'as long',
statements will always resolve to a boolean ... only they may not
do it in a way that is readily understood by everyone.
2. the php engine specifically allows for 'complex expression'
cases testing against a boolean switch value ... not best practice
according to some but very much technically correct according to
the php implementation.
Good explanation -- I think the drum he's beating is that some of use
the switch without actually using the main expression within the
control, such as:
switch($who_cares)
{
case $a = $b:
// do something
break;
case $a > 0:
// do something else
break;
case $a < 0:
// do something elser
break;
}
The control works.
However to him, technically correct means:
switch($a)
{
case 0:
// do something
break;
case 1:
// do something else
break;
case 2:
// do something elser
break;
}
That's what I think he's advocating.
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