Re: ; on the end of the line

From: Date: Thu, 30 Mar 2017 18:19:09 +0000
Subject: Re: ; on the end of the line
References: 1 2  Groups: php.internals 
Request: Send a blank email to internals+get-98691@lists.php.net to get a copy of this message
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. johannes

« previous php.internals (#98691) next »