Closed thekid closed 2 months ago
The reflection library has support for this now, see https://github.com/xp-framework/reflection/releases/tag/v3.2.0 and https://github.com/xp-framework/reflection/releases/tag/v2.15.0
Implemented in https://github.com/xp-framework/compiler/releases/tag/v9.2.0
Once the PR is merged and built into GitHub Actions's 8.4 build, we can remove the featzre availability checks from the PHP 8.4 emitter using the following patch:
diff --git a/src/main/php/lang/ast/emit/PHP84.class.php b/src/main/php/lang/ast/emit/PHP84.class.php
index a23910d..71379f3 100755
--- a/src/main/php/lang/ast/emit/PHP84.class.php
+++ b/src/main/php/lang/ast/emit/PHP84.class.php
@@ -1,6 +1,5 @@
<?php namespace lang\ast\emit;
-use ReflectionProperty;
use lang\ast\types\{
IsArray,
IsFunction,
@@ -20,10 +19,6 @@ use lang\ast\types\{
*/
class PHP84 extends PHP {
use RewriteBlockLambdaExpressions;
- use PropertyHooks, AsymmetricVisibility {
- PropertyHooks::emitProperty as emitPropertyHooks;
- AsymmetricVisibility::emitProperty as emitAsymmetricVisibility;
- }
public $targetVersion= 80400;
@@ -58,25 +53,4 @@ class PHP84 extends PHP {
IsGeneric::class => function($t) { return null; }
];
}
-
- protected function emitProperty($result, $property) {
- static $asymmetric= null;
- static $hooks= null;
-
- // TODO Remove once https://github.com/php/php-src/pull/15063 and
- // https://github.com/php/php-src/pull/13455 are merged
- if (
- !($asymmetric ?? $asymmetric= method_exists(ReflectionProperty::class, 'isPrivateSet')) &&
- array_intersect($property->modifiers, ['private(set)', 'protected(set)', 'public(set)'])
- ) {
- return $this->emitAsymmetricVisibility($result, $property);
- } else if (
- !($hooks ?? $hooks= method_exists(ReflectionProperty::class, 'getHooks')) &&
- $property->hooks
- ) {
- return $this->emitPropertyHooks($result, $property);
- }
-
- parent::emitProperty($result, $property);
- }
}
\ No newline at end of file
PHP 8.4 on Ubuntu is not yet up-to-date with current GIT, see https://github.com/xp-framework/compiler/actions/runs/10643910513/job/29508056545.
PHP 8.4 emitter released in https://github.com/xp-framework/compiler/releases/tag/v9.3.0
Add support for https://wiki.php.net/rfc/asymmetric-visibility-v2
Example
In a nutshell:
RFC status: Accepted
Quoting https://externals.io/message/124622#124838:
Rewriting
To support this in lower PHP versions, we will need to rewrite this to virtual properties, much like readonly support was implemented in #124, along the lines of the following:
See also