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

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

Open
tonix-tuft opened this issue Feb 26, 2015 · 0 comments

Comments

@tonix-tuft
Copy link

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...

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