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

- Thread: https://externals.io/message/307
- Original archive: https://news-web.php.net/php.internals/307
- Started by Ford on 2003-03-26T17:08:25+00:00
- Messages: 3
- Reply by email to internals@lists.php.net
- More for agents: search with https://externals.io/search.md?q={query} · JSON API at https://externals.io/api · documentation at https://externals.io/llms.txt

---

## #307 — Ford — 2003-03-26T17:08:25+00:00

URL: https://externals.io/message/307#307

> -----Original Message-----
> From: Rasmus Lerdorf [mailto:rasmus@lerdorf.com]
> Sent: 26 March 2003 16:42
> To: Ford, Mike [LSS]
 
> > […]
> think it's a less
> > […]
> nothing gained...!
> > […]
> 
> Mike, changing this would break all sorts of stuff, and I 
> think it would
> confuse a lot of people.

Huh???  What would it break?  And I don't see how it would be confusing (in
fact, in my opinion it would be exactly the reverse).

Choosing between "case 0:" and (say) "case_identical 0:" would only be the
same as choosing between == and === in an if statement -- it would just give
the opportunity to do it using the elegant switch structure instead of the
clumsy if...elseif...else chain.

It just seems a shame not to have an === equivalent available within switch
structures -- but, hey, it was only a speculative suggestion, I'm perfectly
happy to bow to contrary opinion, and this is absolutely my last word on the
subject ... ;))

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

---

## #357 — Michael Sims — 2003-03-27T02:17:27+00:00

URL: https://externals.io/message/307#357 · In reply to: #307

>Choosing between "case 0:" and (say) "case_identical 0:" would only be the
>same as choosing between == and === in an if statement -- it would just give
>the opportunity to do it using the elegant switch structure instead of the
>clumsy if...elseif...else chain.

Why not something like this:

$a = 0;

switch (true) {
  case ($a === 'somestring'):
    ...
    break;
  case ($a === 0):
    ...
    break;
}

It's not pretty, but you might like it better than
if...elseif...else...

---

## #365 — Hartmut Holzgraefe — 2003-03-27T09:33:50+00:00

URL: https://externals.io/message/307#365 · In reply to: #357

Michael Sims wrote:
> 
> It's not pretty, but you might like it better than
> if...elseif...else...
> 

no, please ... as it has a much higher WTF factor ...
