Yesterday I had to make some changes in VirtueMart for Joomla 1.0.13. This codebase can be a little confusing sometimes. Believe it or not but this was the first time in my PHP-coding career that I felt the need to be able to simply dump all declared variables, not just the globals in $_REQUEST and so on. Perhaps a testament to how little time I’ve spent working on other people’s code, it’s not much.
So some Googling for just that made me end up on the Xdebug site. It looks like a really nice tool, however the installation procedure held little appeal to me. Besides, I didn’t need all the capabilities, only the ability to dump the variables.
It turns out I should have used the wording “defined” instead of “declared” in my searches. Checking the PHP manual with the words “get defined” will show you the get_defined_vars() function. There is actually a whole slew of get_whatever functions that could be useful in various situations.
So doing print_r(get_defined_vars()) gave me the whole works. Perfect now I wanted to check it out by going “vew source” in Firefox and instantly get prompted with something like “the page needs to be reposted blabla”. What? I just want to view the code! Accepting the repost showed me a HTML source without my printed variables. This is the first time this behavior has happened to me and I’ve got no idea why. Luckily I have the Web Developer toolbar installed so I tried “View Generated Source” and voila!