Re: Re: Switch statement Question
| From: | tedd | Date: | Sat, 31 Jan 2009 14:54:26 +0000 |
| Subject: | Re: Re: Switch statement Question | ||
| References: | 1 2 3 4 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-287483@lists.php.net to get a copy of this message | ||
At 4:16 PM +0100 1/30/09, Jochem Maas wrote:
tedd schreef: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:At 4:43 PM -0500 1/29/09, Frank Stanovcak wrote:"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.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?
// do something elsebreak; 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 elsebreak; 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