Skip to content

Conversation

@matzeeable
Copy link

Hi!

I have added a test case and implementation to support PHP traits as requested here #111 and #149.

Instead of backwards-referencing in a Regexp to check if the use is inside a class, I go the following way:

  • Use T-Regex package to obtain the offset of a found use statement
  • When found, get the content before the match
  • Get all previous class { and namespace { definitions (yeah, multiple namespace { definitions are allowed in PHP)
  • Get the last found match and check if it is a class defintion
  • If yes, skip the trait transformation

Backwards-referencing in a Regexp would be much more "nice", but unfortunately PHP does not support it (I used it in JavaScript before).

RegExp is not the recommend way to do such transformations!! This is a simple workaround which works but you should really consider building your tool on top of an AST parser like php-parser.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

1 participant