A fragment of PHP that really shouldn’t work. I hope nobody ever finds a use for this:
switch($n)
{
case 1;
echo 'one';
break;
case 2;
echo 'two';
break;
case 3;
echo 'three';
break;
}
Tags: php
-
Pingback from php|hampshire » Stupid PHP Tricks: Broken Switch on June 5, 2009 at 2:02 pm
-
And this one?
switch(true) {
case($n==(int) 1);
echo ‘one’;
break;
case ($n==2);
echo ‘two’;
break;
case ($n==3);
echo ‘three’;
break;
}
3 comments
Comments feed for this article
Trackback link: http://www.otton.org/2009/06/05/supid-php-tricks-broken-switch/trackback/