I need a way to see all the defined variables of the current PHP instance.
By currently defined I mean all the globals, all the local to THIS scope and all the locals to other scopes.
Is there something built in?
views:
71answers:
2
+6
A:
For everything in the current scope:
print_r(get_defined_vars());
I don't think there is a solution to dump all variables from all scopes, because you would have to actually run those functions/methods to get a complete and intact map of all available variables (variables could get created, added and removed at runtime).
You may have to look into Unit Testing or code coverage tools to see whether you can use anything from those areas, but it's going to be a lot of work.
What do you need this for?
Pekka
2010-05-12 20:38:45
I am dealing with a huge project (I mean, really, hundred of thousands of lines of code). I some times need to see the "bigger" picture of what is happening.
Itay Moav
2010-05-12 22:47:07
@Itay I see. Did you inherit the project? Is the code documented at all? That kind of overview is best achieved by in-line documentation that phpdoc can make sense of.
Pekka
2010-05-13 08:46:42
@pekka - you are right in all your assumptions, except the ones about documentation :-DDD (i.e. there is no documentation, no meaningful enough symbol names etc)
Itay Moav
2010-05-13 12:53:13
@Itay I see, *that* kind of project! :D
Pekka
2010-05-13 12:58:03
Switch to Java.
2010-05-13 13:04:21
@Walter White - You do know that 100's of thousands of lines in PHP translate to millions in java ;-)
Itay Moav
2010-05-13 13:26:14
If you really want to believe that.As for the root problem, perhaps you can use dtrace if you're on a Solaris platform.
2010-05-13 17:52:47
On the PHP projects I've worked on, I tend to notice more copy and paste as well as fewer design patterns being followed. I agree, on the Java side, development tends to follow patterns more so things may become more complex, but not necessarily more code even if you include the amount of code in the frameworks.PHP is a scripting language, which lends itself to developing a simple solution to a problem quickly. Problem is, while you can develop more quickly because you're less strict, those to do items never get done. So, you're often left with copy and paste and other anti-patterns.
2010-05-13 17:55:20
@Walter I see where you're coming from, but even though PHP is a very permissive language, it *is* possible to develop professional software with it. PHP has a very low barrier of entry, so the proportion of crappy software vs. high-quality software is higher than in a strict language like Java - still, it is possible for a decent developer to build a decent product in PHP, particularly since PHP 5.3.
Pekka
2010-05-13 18:04:46
@Pekka, I agree with your comment, the barrier is much lower.In any case, is it possible for him to use DTrace? He has to be on Solaris to use that tool.
2010-05-14 14:43:01
@Walter I don't know DTrace but I doubt it will helpful, seeing as each function would actually have to be executed - and executed correctly - for all variables to be initialized reliably. I think this can only be done using code that has been optimized for Unit Testing and Code Coverage checking purposes - I can't see any other way how to do this. (Except of course for documenting all variables you spot in the functions. But the fact that you don't need to declare a vairable, but can conjure it out of thin air like `$new_var = "Hello!"` in PHP can make that a tedious task.)
Pekka
2010-05-14 19:46:11
A:
var_dump($GLOBALS);
If a variable is not defined at the time this statement runs, then it is impossible to talk about it as having a value. Variables in "other" scopes don't exist.
{
$a = new myClass();
do stuff
$a->destroy();
}
print "$a has no meaning in this context";
Full Decent
2010-05-13 18:41:17