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

Wrong compiled method of parent #187

Closed
NaokiTsuchiya opened this issue Feb 19, 2022 · 0 comments · Fixed by #188
Closed

Wrong compiled method of parent #187

NaokiTsuchiya opened this issue Feb 19, 2022 · 0 comments · Fixed by #188
Labels

Comments

@NaokiTsuchiya
Copy link
Member

Bug Report

#181 にて親クラスのメソッドのインターセプトが実装されましたが、
メソッドシグネチャにnamescpace外のクラスが記述されるとエラーになります。

How to reproduce

demo/src に以下の2つのクラスを作成します。

<?php
declare(strict_types=1);

namespace Ray\Aop\Demo;

use ArrayIterator;
use Traversable;

class A
{
    public function passIterator(ArrayIterator $iterator): Traversable
    {
        return $iterator;
    }
}
<?php
declare(strict_types=1);

namespace Ray\Aop\Demo;

class B extends A
{
}

demo に以下のファイルを作成し、実行します。

<?php

use Ray\Aop\NullInterceptor;

require __DIR__ . '/bootstrap.php';

$compiler = new Ray\Aop\Compiler(__DIR__ . '/tmp');
$bind = (new Ray\Aop\Bind())->bindInterceptors('passIterator', [new NullInterceptor()]);
$b = $compiler->newInstance(Ray\Aop\Demo\B::class, [], $bind);
$b->passIterator(new ArrayIterator());
PHP Fatal error:  Could not check compatibility between Ray\Aop\Demo\B_3617677882::passIterator(Ray\Aop\Demo\ArrayIterator $iterator): Ray\Aop\Demo\Traversable and Ray\Aop\Demo\A::passIterator(ArrayIterator $iterator): Traversable, because class Ray\Aop\Demo\ArrayIterator is not available in /Users/tsuchiya/work/tsuchiya/Ray.Aop/demo/tmp/Ray_Aop_Demo_B_3617677882.php on line 15

Fatal error: Could not check compatibility between Ray\Aop\Demo\B_3617677882::passIterator(Ray\Aop\Demo\ArrayIterator $iterator): Ray\Aop\Demo\Traversable and Ray\Aop\Demo\A::passIterator(ArrayIterator $iterator): Traversable, because class Ray\Aop\Demo\ArrayIterator is not available in /Users/tsuchiya/work/tsuchiya/Ray.Aop/demo/tmp/Ray_Aop_Demo_B_3617677882.php on line 15

生成されたクラスは以下です。

<?php

declare (strict_types=1);
namespace Ray\Aop\Demo;

use Ray\Aop\WeavedInterface;
use Ray\Aop\ReflectiveMethodInvocation as Invocation;
class B_3617677882 extends \Ray\Aop\Demo\B implements WeavedInterface
{
    public $bind;
    public $bindings = [];
    public $methodAnnotations = 'a:0:{}';
    public $classAnnotations = 'a:0:{}';
    private $isAspect = true;
    public function passIterator(ArrayIterator $iterator) : Traversable
    {
        if (!$this->isAspect) {
            $this->isAspect = true;
            return call_user_func_array([$this, 'parent::' . __FUNCTION__], func_get_args());
        }
        $this->isAspect = false;
        $result = (new Invocation($this, __FUNCTION__, func_get_args(), $this->bindings[__FUNCTION__]))->proceed();
        $this->isAspect = true;
        return $result;
    }
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant