goaop / framework

:gem: Go! AOP PHP - modern aspect-oriented framework for the new level of software development
go.aopphp.com
MIT License
1.66k stars 163 forks source link

Call to undefined method PhpParser\Node\Expr\Variable::toString() #413

Closed jozsika closed 5 years ago

jozsika commented 5 years ago

Hi,

Call to undefined method PhpParser\Node\Expr\Variable::toString() in .../vendor/goaop/framework/src/Instrument/Transformer/MagicConstantTransformer.php on line 100

I get this error when the parsed code contains a dynamic method call using a variable, like $relation = $this->$getter(); from here: https://github.com/yiisoft/yii2/blob/6aa6359bbc76a85d039b8b2d04b39ef7db3d5093/framework/db/BaseActiveRecord.php#L1244

In vendor/goaop/framework/src/Instrument/Transformer/MagicConstantTransformer.php wrapReflectionGetFileName() $methodCallNode->name is the following:

class PhpParser\Node\Expr\Variable#5533 (2) {
  public $name =>
  string(6) "getter"
  protected $attributes =>
  array(6) {
    'startLine' =>
    int(1236)
    'startTokenPos' =>
    int(4242)
    'startFilePos' =>
    int(48240)
    'endLine' =>
    int(1236)
    'endTokenPos' =>
    int(4242)
    'endFilePos' =>
    int(48246)
  }
}

Installed packages versions are:

codeception/aspect-mock            3.0.2    Experimental Mocking Framework powered by Aspects
goaop/framework                    2.3.0    Framework for aspect-oriented programming in PHP.
goaop/parser-reflection            2.0.0    Provides reflection information, based on raw source
nikic/php-parser                   v4.2.0   A PHP parser written in PHP

Downgrading to goaop/framework 2.2.0 solves the problem, so:

codeception/aspect-mock            3.0.2    Experimental Mocking Framework powered by Aspects
goaop/framework                    2.2.0    Framework for aspect-oriented programming in PHP.
goaop/parser-reflection            1.4.1    Provides reflection information, based on raw source
nikic/php-parser                   v3.1.5   A PHP parser written in PHP
lisachenko commented 5 years ago

This issue relates to the new version of nikic/php-parser and goaop/parser-reflection and should be fixed for the 2.x and master branches

thornview commented 5 years ago

I had the same issue as @jozsika with the same dependency versions. As mentioned, downgrading to goaop/framework 2.2.0, with the related dependency downgrades, fixed the problem.

ahmed-abid commented 5 years ago

I suggest these two fixes: https://github.com/goaop/framework/pull/417/files https://github.com/nikic/PHP-Parser/pull/596/files

ddinchev commented 5 years ago

@ahmed-abid @lisachenko it seems that the issue is resolved in master but the fix has not been released as a stable version. Was it just forgotten or there is a known issue with it?

ahmed-abid commented 5 years ago

not yet released

ddinchev commented 5 years ago

So, what would it take to get released?

ddinchev commented 5 years ago

@lisachenko I'm sorry to be bothering again. Can we please have a bugfix version published with the latest master unless there is a particular reason for it to be held back?

lisachenko commented 5 years ago

Hi, @ddinchev! I'm still worrying about releasing master branch, because it isn't well-tested and going to be next major version. Could you please check, how it works for you if you require it explicitly?

ddinchev commented 5 years ago

@lisachenko it works for me with two changes being necessary in AspectMock itself (the current issue here starts with AspectMock anyway). I did a PR for them: https://github.com/Codeception/AspectMock/pull/171

I still am wondering why the above fix does not get released under 2.4.0 for example. If there are issues, they can be addressed, people still can easily freeze their dependencies up to 2.3.x. What do you think?

lisachenko commented 5 years ago

@ddinchev I'm open for discussions and PRs, unfortunately, I haven't time to work on project, this is why some issues are still open.

If your know the way how to fix this issue, then let's do this! )

lisachenko commented 5 years ago

Fixed in 2.3.2 with #419