Reputation:
I have a function with some code in it, but I'm not allowed to touch it (ie: add more code). Is there a way in PHP to get variables defined in that function?
Thank you for helping...
Ok, I've not been very clear. Here's what I'm trying to do.
$hello(function() {
$a = "this is a variable!";
});
I want this code to serve a file (a view), capable of reading variable $a.
I've recently tried playing around with php's reflection and found a way to extract static variables.... don't think there's a way for all other variables, but I'll keep searching.
$obj = new ReflectionFunction($my_closure);
print_r($obj->getStaticVariables());
Upvotes: 0
Views: 109
Reputation: 5259
Variables defined in the function will only be visible within the scope of the function and so have no relevance to any other code on your site.
Upvotes: 5