Req #51016 [Opn->Wfx]: Always associate "else:" followed by colon to an "if:" followed by colon
| From: | cmb@php.net | Date: | Tue, 16 Nov 2021 15:17:38 +0000 |
| Subject: | Req #51016 [Opn->Wfx]: Always associate "else:" followed by colon to an "if:" followed by colon | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-237791@lists.php.net to get a copy of this message | ||
Edit report at https://bugs.php.net/bug.php?id=51016&edit=1
ID: 51016
Updated by: cmb@php.net
Reported by: claude dot pache at gmail dot com
Summary: Always associate "else:" followed by colon to an
"if:" followed by colon
-Status: Open
+Status: Wont fix
Type: Feature/Change Request
Package: Scripting Engine problem
Operating System: *
PHP Version: 5.3.1
-Assigned To:
+Assigned To: cmb
Block user comment: N
Private report: N
New Comment:
> This rule is not convenable when the else/elseif is followed by
> a colon and the last previous if/elseif is not.
Right. However, I wouldn't want to encourage anyone to use this
mixed style. Given that this request is more than ten years old
and got almost no traction, I'm closing as WONTFIX. If you, or
anybody else for that matter, is still interested in this, please
pursue the RFC process[1].
> It should be improved to specify what happens e.g. in the
> following dangling else case:
Done[2].
[1] <https://wiki.php.net/rfc/howto>
[2] <https://github.com/php/doc-en/commit/3725fe1c95b201563518c30e1988b2f32ee099aa>
Previous Comments:
------------------------------------------------------------------------
[2021-04-26 12:19:39] temp at springtimesoftware dot com
1. PHP should work like most other languages: an else should always be associated with the nearest
previous if statement. Period. Any other behavior can be obtained by using curly brackets.
2. Currently, the PHP Manual is incomplete in describing valid sequences of nested ifs, thens, and
elses. It should be improved to specify what happens e.g. in the following dangling else case:
if ($a)
if ($b) b();
else c();
Of course, the "else c();" should be associated with "if ($b) b();".
3. Colons following if, then, or else tokens should result in a syntax error.
4. "elseif" or "elif" (your choice) should be a valid abbreviation for
"else if".
------------------------------------------------------------------------
[2010-02-11 14:03:44] claude dot pache at gmail dot com
Description:
------------
In case of ambiguity, the statements "else" and "elseif" are always
associated to the last previous "if" or "elseif". This rule is not
convenable when the else/elseif is followed by a colon and the last
previous if/elseif is not.
See also: http://bugs.php.net/bug.php?id=838
Reproduce code:
---------------
if(foo):
// some code here
if (bar) baz;
else:
// some code here
endif;
Expected result:
----------------
Since the "else" is followed by a colon (:), it can be associated
*unambiguously* with the last "if" followed by a colon (here,
"if(foo):"), and not with the last "if" (here, "if(bar)").
Actual result:
--------------
Parse error. The "else" is associated with the last "if", and the
following ":" is unexpected.
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=51016&edit=1