Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support complex trait usage scenarios #36

Open
aik099 opened this issue Dec 15, 2024 · 1 comment
Open

Support complex trait usage scenarios #36

aik099 opened this issue Dec 15, 2024 · 1 comment

Comments

@aik099
Copy link
Member

aik099 commented Dec 15, 2024

PHP Docs: https://www.php.net/manual/en/language.oop5.traits.php

  1. if there is a class member (property/member), then its declaration wins over the declaration from the trait (important for the bc command)
  2. multi-trait conflict resolution via insteadof keyword (an edge case, but good to have; not sure how ReflectionClass would get me that):
use A, B {
    B::smallTalk insteadof A;
}
  1. trait method/property/constant renames on the fly using as keyword (can retrieve via ReflectionClass::getTraitAliases):
use A, B {
    B::bigTalk as talk;
}
  1. trait method/property/constant visibility change on the fly using as keyword (not sure how ReflectionClass would get me that):
use HelloWorld { sayHello as private myPrivateHello; }
@aik099
Copy link
Member Author

aik099 commented Dec 16, 2024

Research results:

  1. the PHP's built-in ReflectionClass trait-provided constants/properties/methods as if they were declared on a class itself
  2. the Code-Insight library doesn't have tests to confirm, that behavior (need to add them)
  3. the goaop/parser-reflection library used in this project:
  4. the Roave/BetterReflection library has the code for processing trait adaptations ( see https://github.com/Roave/BetterReflection/blob/0f82edc5d371730e530de90a5e3ce4de576cbb7d/src/Reflection/ReflectionClass.php#L1494 )
  5. constants in traits allowed since PHP 8.2
  6. visibility of class constants allowed since PHP 7.1
  7. aliasing/scope changing for trait properties/constants isn't supported in PHP itself

Plan:

  1. make traits work in goaop/parser-reflection in 1.x branch and up
  2. all tests in this project to confirm, that it works as expected

P.S.
Current trait support in this project is pretty basic - use trait-provided constants/properties/methods in the main class as-is if there is no such constant/property/method in the class itself.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant