xp-framework / compiler

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

Arbitrary static variable initializers #162

Closed thekid closed 1 year ago

thekid commented 1 year ago

Support https://wiki.php.net/rfc/arbitrary_static_variable_initializers natively in PHP 8.3 emitter.


Currently, this functionality is emulated by using the following, see implementation status:

use util\Date;

// What gets written
function start() {
  static $now= new Date();

  var_dump($now);
}

// What is emitted
function start() {
  static $now; $now??= new Date();

  var_dump($now);
}
thekid commented 1 year ago

RFC has been accepted, now need to wait for https://github.com/php/php-src/pull/9301 to be merged before being to change PHP 8.3 emitter to emit native code for this.

thekid commented 1 year ago

Merged in https://github.com/php/php-src/commit/0b1d750d91f75cf62f6ba1efb6df816de71ff81c

thekid commented 1 year ago

Updated https://github.com/xp-framework/compiler/wiki/Implementation-status

thekid commented 1 year ago

Released in https://github.com/xp-framework/compiler/releases/tag/v8.14.0