RE: Make switch/case to type sensitive comparison in PH P 5?

php.internals

Ford, Mike [LSS]

23 years ago
> -----Original Message----- > From: Zeev Suraski [mailto:zeev@zend.com] > Sent: 24 March 2003 17:58 > To: Joey Smith > > At 05:07 24/03/2003, Joey Smith wrote: > >I was reminded tonight of the following 'feature' of switch: > > > >$a = 0; > >switch($a) { > > case 'somestring': echo 'Bug?'; break; > > case 0: echo 'Not a bug'; break; > >} > > > >This will echo 'Bug?' with PHP 4. It seems more logical to > have switch > >comparing with T_IS_IDENTICAL than with T_IS_EQUAL. Is this > something that > >might be changed as we move to PHP 5.0?> > It's not a 'feature', it's a feature. It's not likely to > change, dynamic > type conversion is one of the foundations of PHP.
Well, yes, but we have == and === for other situations, so some sort of analogue for use in switches would be nice (I've been bitten by this one more than once myself!). I'd love to see, say, case_identical for requesting an === comparison, with case continuing as before to do an == comparison. Cheers! Mike --------------------------------------------------------------------- Mike Ford, Electronic Information Services Adviser, Learning Support Services, Learning & Information Services, JG125, James Graham Building, Leeds Metropolitan University, Beckett Park, LEEDS, LS6 3QS, United Kingdom Email: m.ford@lmu.ac.uk Tel: +44 113 283 2600 extn 4730 Fax: +44 113 283 3211

Zeev Suraski

23 years ago
At 03:27 25/03/2003, Ford, Mike [LSS] wrote:
>I'd love to see, say, case_identical for requesting an === comparison, with >case continuing as before to do an == comparison.
I'd really not love to see it :) Use an if-else chain of === comparisons instead if that's what you really need. Zeev