Table of Contents

PHP RFC: Language Constructs Syntax Changes

Language constructs syntax changes regarding the need for parentheses for declare and __halt_compiler stamenents.

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:

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:

__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.

Implementation