rfc:keywords_as_identifiers
This is an old revision of the document!
PHP RFC: Extended keyword support
- Version: 1.0
- Date: 2013-09-14
- Author: Bob Weinand, bobwei9@hotmail.com
- Status: Under Discussion
- First Published at: http://wiki.php.net/rfc/keywords_as_identifiers
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.
An example what is possible with this patch:
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))); }
Typehints
Currently when using array or callable as typehint, the old behaviour is preferred over comparing if it's a class/interface named array or callable. I'm not sure if we should just allow both in this special case.
Proposed PHP Version(s)
This RFC should go into next PHP 5.x.
Patch
- The patch is against master
- Pull request is at https://github.com/php/php-src/pull/438
References
- Mailing List thread at http://markmail.org/message/7rn4mbwkbytqa3ig
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.1379254626.txt.gz · Last modified: 2017/09/22 13:28 (external edit)