Re: Re: Switch statement Question

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



"tedd" <tedd.sperling@xxxxxxxxx> wrote in message 
news:p06240801c5aa0ed7db08@[192.168.1.101]...
> 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

very true since this is the way it is taught in every book.  Php, however, 
allows for other uses that weren't "technically" in the original plan for 
this command from other languages.  The problem is I shave my head, so I 
have no hairs to split over this one.  :)

Frank 



-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux