Bug #75138 [Com]: Nested "IF" triggers Exception when it is before "else:" or "elseif:".

From: Date: Thu, 12 Apr 2018 05:45:23 +0000
Subject: Bug #75138 [Com]: Nested "IF" triggers Exception when it is before "else:" or "elseif:".
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-214707@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=75138&edit=1

 ID:                 75138
 Comment by:         jcmarchi at gmail dot com
 Reported by:        jcmarchi at gmail dot com
 Summary:            Nested "IF" triggers Exception when it is before
                     "else:" or "elseif:".
 Status:             Not a bug
 Type:               Bug
 Package:            *Programming Data Structures
 Operating System:   All
 PHP Version:        Irrelevant
 Block user comment: N
 Private report:     N

 New Comment:

Why are you replying to a closed dead thread from last year? Lack of attention? Boredom? Trolling
for fun? Does someone need a hug? Hum?

You missed the party. It is all resolved. @requinix already answered it all when he pointed that the
second semicolon changes the meaning of the structure by introducing another (empty) statement thus
breaking the if/else pair apart, avoiding the "dangling else" problem. He also said:
it's syntax. No bug, no problem, no issue. Simply "a syntax" (whatever it may mean)!

Problem solved, OK? I am good with that and I'd already moved on... News flash: There is life
after PHP, did you know? You can move on too... 

Notwithstanding, let take this opportunity to apologize for the presented "code sample".
Now I understand how beneath your "impeccable ultra-high standard coding levels" it was.
It should have been a simple "code sample", something to pinpoint the issue and allow a
quick TRY OUT of the proposed problem (NOT A BUG, NOT A BUG!!!!), and I failed to understand the
rule that it should have been written as a poetry.

Silly me... I don't know why I assumed people here would have enough intelligence to understand
what a "code sample" is: a piece of code NOT extracted from an application but built to be
a simple PROBLEM DEMONSTRATION. Next time I promise I will try to raise my standards to show off my
coding skills (which is what this place is all about, right?). I promise nothing less than a couple
of hundred lines of code properly namespaced, with Classes and inheritances, Traits, a few
recursions here and there, some special methods to make it nice and callables all over the place to
make it fancy, etc.. All nine yeards... (Ops... No no no!!! There will be no next time. I AM OUT OF
HERE!!!).

Let's do better: while I am writing a rule in my email to send messages from this thread to
/dev/null, pretending I give a damn for whatever you say or think, you should stop replying to dead
threads and go back pretending you actually do anything about "chopping real bugs"...
go... go... 

P.S.: "Why should you write such a bad English?"


Previous Comments:
------------------------------------------------------------------------
[2018-04-11 10:44:42] edelgrande at brennerplatz dot com

Others already wrote in different ways what I think.

Why should you write such a bad code?
In order to be consistent, please use the same syntax in all the snippet. I could be a colleague who
should put his hands over your code!
This way, you can see there is much more clarity and no complex behaviour difficult to understand
and analyse, be it a bug or not.

Keep it simple, there are real PHP bugs out there we already have to cope with!

<?php
if (isset($bar)):
	if (isset($foo)):
		echo "Both are set.";
	endif;
elseif (isset($foo)):
	echo "Only 'foo' is set.";
else:
	echo "Only 'bar' is set.";
endif;
?>

------------------------------------------------------------------------
[2017-08-31 16:15:29] peehaa@php.net

I am sorry for you, but as several people by now have stated: this is not a bug.

No matter how many personal attacks on volunteers or how loud you are shouting it will not the
status of this bug report. :-)

At this point I see no reason to keep going at it.

So I would suggest you to do just that.

Sorry, but your problem does not imply a bug in PHP itself.  For a
list of more appropriate places to ask for help using PHP, please
visit http://www.php.net/support.php as this bug system
is not the
appropriate forum for asking support questions.  The support channels will be able to provide an
explanation
for you.

Thank you for your interest in PHP.

------------------------------------------------------------------------
[2017-08-31 16:15:23] jcmarchi at gmail dot com

Ok. Very well... I can accept it as not being a "BUG", but a "NEW SYNTAX
requirement" (rules are rules). Next, it must be added to the language manual definition in
regards to semicolon usage and purpose.

I then propose the following addition to the PHP official documentation:

====================
When using "alternative syntax for control structures" observe the fact that when an
"IF" statement is required to be nested into another IF-ELSEIF-ELSE block and it casually
ends up being the last statement of the nested block, it is a LANGUAGE REQUIREMENT to terminate it
with double semicolon (;;) to prevent the "dangling else" effect.
====================

Or, better, we can add it to the same (miss)interpretation concept, keeping documentation standards:

====================
Note:
Mixing syntaxes in the same control block is not supported.

Note:
A nested "if" statement immediately before an "else:" or "elseif: "
statement in control block is not supported.
====================

Or, even better! Let's simply ignore it all and leave it as it is. What harm can an extra
";" do anyway, right?

Well done everyone. Good job!

------------------------------------------------------------------------
[2017-08-31 14:34:00] requinix@php.net

If you want a fifth opinion, I agree with peehaa, nikic, rhsoft, and yohgaki: this isn't a bug.

The second semicolon you're making a fit about changes the meaning of the structure. It
introduces another statement (even if empty) and breaks the if/else pair apart, thus avoiding the
dangling else problem. https://3v4l.org/0vsMV
It's not a workaround. It's syntax.

------------------------------------------------------------------------
[2017-08-31 14:20:35] jcmarchi at gmail dot com

@peehaa, you should re-open this BUG report because IT IS a bug! Or, at least, have the decency to
gather a second opinion about it. You came to a conclusion too quickly and based on a sole visual
analysis of the code samples (I bet you didn't even try some scenarios, did you?), and also by
misinterpreting the PHP manual guidance... :S

If a double semicolon ";;" or a semicolon after the closing curly bracket "};"
requirement to fix a code parsing problem is not considered a bug, then I don't know what will
ever be.

By keeping this BUG REPORT open, other PHP developers (more willing to really make PHP better), will
have a chance to look into it and come up with a real solution.

Thank you.

------------------------------------------------------------------------


The remainder of the comments for this report are too long. To view
the rest of the comments, please view the bug report online at

    https://bugs.php.net/bug.php?id=75138


--
Edit this bug report at https://bugs.php.net/bug.php?id=75138&edit=1


Thread (19 messages)

« previous php.bugs (#214707) next »