On Thu, Mar 30, 2017 at 12:19 PM, Johannes Schlüter <johan...@schlueters.de>
wrote:

> On Do, 2017-03-30 at 00:07 -0700, Davey Shafik wrote:
> > Notice each of these has two statements. (Note: I don't think any of
> > these
> > are particularly good ways to write readable code, but they are all
> > syntactically valid code).
>
> The imo more relevant cases are the one where an optional semicolon
> causes unclear behavior. Consider we make it optional, what is the
> behavior of this code:
>
> <?php
> $a = [1, 2, 3]
> [rand(0, 2)]
> var_dump($a)
> ?>
>
> $a could either be an array with three elements or a single integer
> value which is randomly chosen out of the array. Requiring a statement
> separator like semicolon makes this clear.
>
> > While I know some languages make semicolons optional (javascript), or
> > omit them entirely (python),  semicolons in PHP will not be going
> > away (or optional) any time soon.
>
> JavaScript shouldn't be our role model here - it has relatively complex
> rules for this (essentially "if treating a following line as belonging
> to the statement leaves valid code then treat it as part of the same
> statement else terminate the statement on the new line")
> Python does this by requiring indention on the continuing line. As PHP
> isn't whitespace-programming this isn't applicable for s either, while
> it's a way more consistent design than JavaScript in that regard.
>

I would also point out, that I haven't worked on a JavaScript project in
ages where the conventions / rules of that project allow leaving off
semi-colons. While the language may make it acceptable, most organizations
have rules requiring semi-colons. The reason is to avoid the disambiguation
as Johannes has pointed out.


>
> johannes
>
> --
> PHP Internals - PHP Runtime Development Mailing List
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>

Reply via email to