rfc:keywords_as_identifiers

This is an old revision of the document!


PHP RFC: Your Title Here

Introduction

This RFC aims to remove some restrictions which are due to the fact that keywords are not included in T_STRING.

Proposal

Concretely this patch enables:

  • all keywords for
    • method names
    • class constant names
    • declare directive names
  • a limited set of keywords * for
    • class names
    • trait names
    • interface names
    • goto label names

* This includes all keywords except

  • catch
  • finally
  • case
  • default
  • exit
  • else
  • elseif
  • endif
  • endwhile
  • endfor
  • endforeach
  • enddeclare
  • endswitch

It is necessary to exclude them due to limitations of bison/yacc grammar.

namespace Test {
    class List {
        const default = 0;
        public $case = array(array(self::default));
 
        public static function echo (List $instance) {
            var_dump($instance->case);
        }
 
        public function new (array $entry) {
            $this->case[] = $entry;
            return $this;
        }
    }
}
 
namespace {
    \Test\List::echo((new Test\List)->new(array(1)));
}

Proposed PHP Version(s)

This RFC should go into next PHP 5.x.

Patch

References

Rejected Features

  • Initially the patch contained also some support for functions, namespaces and constants which was removed later due to some resulting syntactic inconsistencies
rfc/keywords_as_identifiers.1379247739.txt.gz · Last modified: 2017/09/22 13:28 (external edit)