Skip to content

Extract reflection to its own library #338

@thekid

Description

@thekid

Scope of Change

This RFC suggests extracting reflection to its own library, while the type system will continue to exist.

Rationale

Reflection is a big block of code with quite a bit of legacy, including an outdated concept of annotations which doesn't fit PHP 8 attributes well.

Functionality

This is the lang.reflect package, which will be replaced by https://github.com/xp-framework/reflection except for the Proxy class, which we might extract to its own library or simply move to the mocking library:

package lang.reflect {

  public interface lang.reflect.InvocationHandler

  public abstract class lang.reflect.Modifiers
  public class lang.reflect.ClassParser
  public class lang.reflect.Constructor
  public class lang.reflect.Field
  public class lang.reflect.Method
  public class lang.reflect.Module
  public class lang.reflect.Package
  public class lang.reflect.Parameter
  public class lang.reflect.Proxy
  public class lang.reflect.Routine
  public class lang.reflect.TargetInvocationException
}

The lang.XPClass class will be stripped down to its essentials, where it will serve the purpose of reflecting value types.

Security considerations

None.

Speed impact

Reduces the size of XP core:

$ cloc-1.82.pl src/main/php/lang/reflect/ src/main/php/lang/XPClass.class.php
      13 text files.
      13 unique files.
       1 file ignored.

github.com/AlDanial/cloc v 1.82  T=0.06 s (221.4 files/s, 58222.3 lines/s)
-------------------------------------------------------------------------------
Language                     files          blank        comment           code
-------------------------------------------------------------------------------
PHP                             13            298           1148           1972
-------------------------------------------------------------------------------
SUM:                            13            298           1148           1972
-------------------------------------------------------------------------------

Dependencies

Generics.

Related documents

xp-framework/unittest#43

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions