AOP-PHP / AOP

AOP in PHP
Other
565 stars 95 forks source link

getStartLine() or getEndLine() of ReflectionFunction don't work as expected and return 'null' when registering an aspect #90

Open tonix-tuft opened 9 years ago

tonix-tuft commented 9 years ago

Hi, I have noticed that if I have a file with the following PHP code:

<?php

//*
aop_add_after("**->*()", function(AopJoinPoint $joinPoint) {
        // advice's body
});
//*/

function myFunc($param1, $param2) {
    //
    //
    //
    echo "myFunc";
}

$r = new ReflectionFunction("myFunc");
ReflectionFunction::export("myFunc");

var_dump($r->getName());
var_dump($r->getStartLine());
var_dump($r->getEndLine());

var_dump($r->getStartLine()); and var_dump($r->getEndLine()); will both output an unexpected null. If I comment the code which adds the advice:

<?php

/*
aop_add_after("**->*()", function(AopJoinPoint $joinPoint) {
        // advice's body
});
*/

function myFunc($param1, $param2) {
    //
    //
    //
    echo "myFunc";
}

$r = new ReflectionFunction("myFunc");
ReflectionFunction::export("myFunc");

var_dump($r->getName());
var_dump($r->getStartLine());
var_dump($r->getEndLine());

Everything works as expected and var_dump($r->getStartLine()); and var_dump($r->getEndLine()); both respectively output:

int 9 int 14

So it seems that when an advice is added some methods of the Reflection API (in this case _ReflectionFunction->getStartLine()_ and _ReflectionFunction->getEndLine()_, didn't test other methods, doesn't behave like expected...)

EDIT: it seems that only the first method of ReflectionFunction() actually returns its return value properly, if I change those 'var_dump's above to:

var_dump($r->getStartLine()); # instead of 'var_dump($r->getName());'
var_dump($r->getStartLine());
var_dump($r->getEndLine());

Only the first var_dump outputs its return value properly, the other two return null...