-
Notifications
You must be signed in to change notification settings - Fork 1
Description
Scope of Change
This RFC suggests changing the PHP language support in the XP Compiler to support all future PHP features (at the time of writing, PHP 7). This would mean you could already start writing PHP 7 code, and could transpile it for running on older, PHP 5.5, environments.
Rationale
Ease adoption of new language features, decouple from slowly adopting production platforms and environments.
Functionality
Design principles
- The future, now!
- Valid PHP passes through the compiler untouched (except alternative syntax)
- Output is as close as possible line/offset/whitespace wise
Compilation
Compilation can either be done explicitly by calling xcc or by using the JIT compiler.
$ xcc -E php5.5 -sp src/main/php -o target/ # Translates PHP 5.6, 7.0
$ xcc -E php5.6 -sp src/main/php -o target/ # Translates PHP 7.0 features only
$ xcc -E php7.0 -sp src/main/php -o target/ # Copy-through, more or less
# ...Features
The following are easy:
- Primitive type hints
- Return types
- Anonymous classes
- Property types
- Spaceship operator
- Null coalesce
- Unicode escapes
- Group use declarations
- Static class constructor
- Trailing commas (for arrays and maps, function calls and in various other places).
These need more investigation:
- Generator delegation - yield from
- Context sensitive lexer - might be possible via
__call... - Named arguments
These might not work in a fast and reliable way:
Experimental support could be added for features currently under discussion:
- Additional splat operator usage
- Named parameters
- Enum - like in Hack language
- Union types
- Nullsafe operator
We could also add Hack language features
- Attributes -> Annotations
- Array types -
array<string>andarray<string, Object> - Generics -> Transform to XP generics?
- Hack lambdas
- Constructor argument promotion
We might want to include support for PHP 5.6:
Security considerations
Speed impact
Dependencies
Related documents
Inspired by http://channel9.msdn.com/Events/Build/2015/3-644