This is an old revision of the document!
PHP RFC: Language Constructs Syntax Changes
- Version: 0.9
- Date: 2020-07-04
- Author: Michał Marcin Brzuchalski, brzuchal@php.net
- Status: Draft
- 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 declare
and _
_halt_compiler stemenents.
===== Introduction =====
In 25yrs history, many language constructs were allowed in different forms depending on the context.
A
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
print can be used as a function
but they don't require parentheses no matter of context. 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.
===== Proposal =====
The proposal is to bring more sanity into the language by relaxing restrictions in some language constructs.
==== Allow skip of parentheses for declare ====
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>
declare strict_types = 1;
declare ticks = 1;
declare encoding = 'ISO-8859-1';
</code>
Allowing also to group them into one statement:
<code php>
declare strict_types = 1, ticks = 1, encoding = 'ISO-8859-1';
</code>
<blockquote>This proposal doesn't influence a declare syntax of ticks with additional statement block!</blockquote>
==== 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.
__halt_compiler(); // syntax error
Therefore the proposal is to allow skip of parentheses as in the example:
__halt_compiler;
Backward Incompatible Changes
None.
Proposed PHP Version(s)
PHP 8.0.
RFC Impact
To SAPIs
None.
To Existing Extensions
None.
To Opcache
None.
New Constants
None.
Proposed Voting Choices
This is a language change and requires 2/3 majority in 4 separate pools with simple Yes/No options.