xp-framework / compiler

Compiles future PHP to today's PHP.
19 stars 0 forks source link

Add emitter to create property type checks for PHP < 7.4 #129

Closed thekid closed 2 years ago

thekid commented 2 years ago

This pull request makes it possible to emit code for PHP versions < 7.4 which will simulate typed properties as described in https://wiki.php.net/rfc/typed_properties_v2.

Usage

By means of the -e switch on the command line:

$ xp compile -t php:7.0 -a php:virtual-property-types <in> <out>
#                       ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

Important

The emitter is not enabled by default as a) it does not work with static properties due to a limitation in PHP and b) the generated code is much slower than its native implementation. So instead of a "prune" option (as asked for by @Danon in #119), users will have to explicitely add this command line switch to generate code which behaves the same in all PHP versions.