rfc:language-constructs-syntax-changes

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Next revision
Previous revision
rfc:language-constructs-syntax-changes [2020/07/04 07:25] – created brzuchalrfc:language-constructs-syntax-changes [2020/07/22 08:36] (current) – withdrawning brzuchal
Line 3: Line 3:
   * Date: 2020-07-04   * Date: 2020-07-04
   * Author: Michał Marcin Brzuchalski, <brzuchal@php.net>   * Author: Michał Marcin Brzuchalski, <brzuchal@php.net>
-  * Status: Draft+  * Status: Withdrawn
   * Target Version: PHP 8.0   * Target Version: PHP 8.0
   * First Published at: http://wiki.php.net/rfc/language-constructs-syntax-changes   * First Published at: http://wiki.php.net/rfc/language-constructs-syntax-changes
  
-Language constructs syntax improvements/changes.+Language constructs syntax changes regarding the need for parentheses for ''declare'' and ''_''''_halt_compiler'' stamenents.
  
 ===== Introduction ===== ===== Introduction =====
 In 25yrs history, many language constructs were allowed in different forms depending on the context. In 25yrs history, many language constructs were allowed in different forms depending on the context.
  
-Some language constructs like ''declare'' which are not functions and therefore cannot be used as a function  +''declare'' statement which is a language construct and not a function cannot be used as a function  
-nor in write context require parentheses while some language constructs like ''print'' can be used as a function +nor in write context but require parentheses while some language constructs like ''print'' can be used as a function 
 but they don't require parentheses no matter of context. but they don't require parentheses no matter of context.
  
-Another language constructs like ''exit'' or ''die'' are allowed to be used as a function but also allows to skip +The same goes to ''_''''_halt_compiler'' statement which cannot 
-parentheses if no argument is passed in write context which has no value.+be used as a function nor in write context because it's not an expression and only looks like that.
  
-There's also an ''assert'' statement which used as a function returns assertion result but only if a specific 
-INI directive ''zend.assertions'' is different than -1 and when that is equal to -1 it always returns true 
-giving false-positive results. 
  
 ===== Proposal ===== ===== Proposal =====
-The proposal is to bring more sanity into the language by adding/relaxing restrictions in some language constructs.+The proposal is to bring more sanity into the language by relaxing restrictions in some language constructs.
  
 ==== Allow skip of parentheses for declare ==== ==== Allow skip of parentheses for declare ====
-A ''declare'' directive id not a function but a language construct therefore the proposal is to allow use it without parentheses in cases when a simple const value expresses a specific declare directives value:+A ''declare'' statement is not a function but a language construct and cannot be used as an expression. 
 +Therefore the proposal is to allow use it without parentheses:
 <code php> <code php>
 declare strict_types = 1; declare strict_types = 1;
Line 42: Line 40:
  
 ==== Allow to skip parentheses for compiler halt ==== ==== Allow to skip parentheses for compiler halt ====
-Some language constructs like ''_''''_halt_compiler'' are language constructs instructing parser +language construct like ''_''''_halt_compiler'' is a statement and cannot be use used as an expression. 
-to stop parsing. It is the one also which looks like a function and therefore it always require +This language construct stops parsing. 
-parentheses but it can never be used as a function in write context cause it's considered a syntax error.+It looks like a function and it always requires parentheses but it can never be used as a function nor in write context
 + cause it's considered a syntax error.
  
 <code php> <code php>
-__halt_compiler(); // syntax error+$foo = __halt_compiler(); // syntax error
 </code> </code>
  
Line 54: Line 53:
 __halt_compiler; __halt_compiler;
 </code> </code>
- 
-==== Require parentheses in constructs allowed to be used like a function ==== 
-A ''print'' is a language construct and it doesn't require parentheses. 
-Therefore when used in a write context it still doesn't look like a function. 
- 
-Some language constructs like ''echo'' and ''print'' can be used with parentheses or without them. 
-The difference in both is that ''echo'' cannot be used in write context currently so there's 
-no issue there. The thing is that ''print'' when used as a function in write context looks more like it than a statement. 
- 
-The proposal is to require use of parentheses for ''print'' //(only)// when used in write context. 
-<code php> 
-false or print("always returns 1"); 
-</code> 
- 
-==== Forbid use of language constructs in write context which never return ==== 
-Some language constructs like ''exit'' and ''die'' are language constructs and can be used as a function. 
-The fact that they allow skipping parentheses if no value is passed makes no sense in write context because of the fact they never return a value. 
- 
-Therefore the proposal is to consider use of ''exit'' and ''die'' in write context when assigning a value a syntax error  
-when used like in example: 
-<code php> 
-$foo = exit; // should be parse error 
-$foo = die; // same here 
-</code> 
- 
  
 ===== Backward Incompatible Changes ===== ===== Backward Incompatible Changes =====
-These will no longer be considered valid syntax: +None.
-<code php> +
-$foo = exit; +
-$foo = die; +
-false or print "foo"; +
-</code> +
- +
-This will be considered a valid syntax: +
-<code php> +
-__compiler_halt; +
-</code>+
  
 ===== Proposed PHP Version(s) ===== ===== Proposed PHP Version(s) =====
Line 108: Line 72:
 ==== New Constants ==== ==== New Constants ====
 None. None.
- 
-===== Future Scope ===== 
-Deprecate non-function like language constructs to be allowed with parentheses in future. 
  
 ===== Proposed Voting Choices ===== ===== Proposed Voting Choices =====
 This is a language change and requires 2/3 majority in 4 separate pools with simple Yes/No options. This is a language change and requires 2/3 majority in 4 separate pools with simple Yes/No options.
- 
-===== Patches and Tests ===== 
-TBD. 
  
 ===== Implementation ===== ===== Implementation =====
-TBD+  * [[https://github.com/php/php-src/pull/5808|Allow declare w/o parentheses]] 
 +  * [[https://github.com/php/php-src/pull/5809|Allow __halt_compiler w/o parentheses]]
rfc/language-constructs-syntax-changes.1593847547.txt.gz · Last modified: 2020/07/04 07:25 by brzuchal