Skip to content

PHP7 – Context Sensitive Lexer

In PHP7 Reserved Word Restrictions was loosen. There are currently 64 keywords reserved by PHP and some of them would be very useful as a method names to user side to define clear API.

Globally reserved words as property, constant, and method names within classes, interfaces, and traits are now allowed. This reduces the surface of BC breaks when new keywords are introduced and avoids naming restrictions on APIs.

This is a list of currently globally reserved words that will become semi-reserved which means we can use as property, constant, and method names within classes, interfaces, and traits.

callable  class  trait  extends  implements  static  abstract  final  public  protected  private  const
enddeclare  endfor  endforeach  endif  endwhile  and  global  goto  instanceof  insteadof  interface
namespace  new  or  xor  try  use  var  exit  list  clone  include  include_once  throw  array
print  echo  require  require_once  return  else  elseif  default  break  continue  switch  yield
function  if  endswitch  finally  for  foreach  declare  case  do  while  as  catch  die  self parent

The only limitation is that the class keyword still cannot be used as a constant name, otherwise it would conflict with the class name resolution syntax (ClassName::class).

 // 'list', 'forEach', and 'for' were previously unusable
class Collection {
     
    public function forEach(callable $callback) { /* */ }
    public function list() { /* */ }
    public function for() { /* */ }

}

That is it.

0 0 votes
Article Rating
Subscribe
Notify of
guest

0 Comments
Inline Feedbacks
View all comments