PHP RFC: Language Constructs Syntax Changes
- Version: 0.9
- Date: 2020-07-04
- Author: Michał Marcin Brzuchalski, firstname.lastname@example.org
- Status: Withdrawn
- Target Version: PHP 8.0
- First Published at: http://wiki.php.net/rfc/language-constructs-syntax-changes
Language constructs syntax changes regarding the need for parentheses for
In 25yrs history, many language constructs were allowed in different forms depending on the context.
declare statement which is a language construct and not a function cannot be used as a function
nor in write context but require parentheses while some language constructs like
The same goes to
_halt_compiler statement which cannot
be used as a function nor in write context because it's not an expression and only looks like that.
The proposal is to bring more sanity into the language by relaxing restrictions in some language constructs.
Allow skip of parentheses for declare
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:
declare strict_types = 1; declare ticks = 1; declare encoding = 'ISO-8859-1';
Allowing also to group them into one statement:
declare strict_types = 1, ticks = 1, encoding = 'ISO-8859-1';
This proposal doesn't influence a declare syntax of ticks with additional statement block!
Allow to skip parentheses for compiler halt
A language construct like
_halt_compiler is a statement and cannot be use used as an expression.
This language construct stops parsing.
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.
$foo = __halt_compiler(); // syntax error
Therefore the proposal is to allow skip of parentheses as in the example:
Backward Incompatible Changes
Proposed PHP Version(s)
To Existing Extensions
Proposed Voting Choices
This is a language change and requires 2/3 majority in 4 separate pools with simple Yes/No options.