Hi Ilija,
Ilija Tovilo wrote:
Looking through the language grammer I discovered that switch cases can also be
terminated with a `;` instead of a `:`.
```
switch ($i) {
case 1;
return 1;
default;
return 2;
}
```
https://3v4l.org/o7nD8
This is in fact documented:
https://www.php.net/manual/en/control-structures.switch.php
What's the reasoning behind this? I find it weird an inconsistent.
For whatever reason, I somehow remember that this dates to at least
PHP/FI 2.0, which means it's as least as old as me (24 years… no, I was
not involved with PHP back then ;). And indeed, the case statement is
mentioned in the manual (https://www.php.net/manual/phpfi2.php#lang),
with an example to be found in
https://museum.php.net/php2/php-2.0.tar.gz under php-2.0/test/lang/003.tst:
--TEST--
Simple Switch Test ...
--POST--
--GET--
--FILE--
<?$a=1;
switch($a);
case 0;
echo "bad";
break;
case 1;
echo "good";
break;
default;
echo "bad";
break;
endswitch>
--EXPECT--
Content-type: text/html
good
Being able to use a colon instead of a semicolon here is, I guess, a
more modern thing. Was it PHP 3 or PHP 4 that changed this? Who knows.
I don't think it's hurting anyone as it is… can we leave it in peace? :)
Thanks,
Andrea
--
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: http://www.php.net/unsub.php