Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:109364 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 65386 invoked from network); 26 Mar 2020 23:42:39 -0000 Received: from unknown (HELO localhost.localdomain) (76.75.200.58) by pb1.pair.com with SMTP; 26 Mar 2020 23:42:39 -0000 To: internals@lists.php.net References: Date: Thu, 26 Mar 2020 23:07:40 +0100 User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.14; rv:52.0) Gecko/20100101 Firefox/52.0 SeaMonkey/2.49.2 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit X-Posted-By: 46.59.72.204 Subject: Re: semicolon terminator for switch cases From: ajf@ajf.me (Andrea Faulds) Message-ID: 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-- --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