Skip to content

Instantly share code, notes, and snippets.

@brzuchal
Created July 4, 2020 05:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save brzuchal/85f743e0de040dc4c952ace3d13e1dea to your computer and use it in GitHub Desktop.
Save brzuchal/85f743e0de040dc4c952ace3d13e1dea to your computer and use it in GitHub Desktop.
PHP Language Syntax Improvement
<?php
# Proposal
// remove parens gives a clear sign that it's not a function
declare strict_types = 1;
// require parens in constructs allowed to be used like a function
false or print("always returns 1");
// exit and die never returns value like echo and __halt_compiler
$foo = exit; // should be parse error
$foo = die; // same here
# Background
// since declare is not a function should not look like a function
// this language construct has to be very first in file
// also it doesn't return any value
declare(strict_types = 1);
// some language constructs can be used only as a statement
echo "works as a statement";
// therefore they do not return anything and cannot be used
// in write context, this is considered parse error
$foo = echo "no matter of parentheses existence";
false or echo "similar here";
// above mentioned is not a valid point for print which
// is also a language construct but more often used like
// a function with parens
false or print "foo";
// similar for exit and die which are not a functions either
// but a language construct although it can be used as an expression
// which suggest to put the same requirement on print in write context
false or die('like a function');
// there is also a __halt_compiler which is not a function
// but can be used only like a function and not in write context
// giving always parse error
$foo = __halt_compiler();
false or __halt_compiler();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment