When working with a friend of mine, he kept asking me the arguments for functions, and when I told him to try api.drupal.org or my favorite drupalfunctions.com he told me that sometimes it is not the case and what he wanted to know was what was really being past to the function.
Well I told him that was quite, simple just dpm() the arguments of the function. Looking at me bewilder, I showed him the function func_get_args() and how when it is combines with dpm() it will show you exactly what is called.
so in a simple hook like hook_node_view() you can find out what is really being passed.
/** * Implements hook_node_view(). */ function foo_node_view() { dpm(func_get_args()); }
doing this will always tell you what is happening.
Another thing I also showed him. was the __FUNCTION__ which gives you a string of the current function. so adding
dpm(__FUNCTION__);
to any function will tell you when the function is called, and doing this means that you can cut and past this into any function without any changes. Makes for easy debugging. Also you can try __FILE__ or __LINE__ and you can fine more magic contants at http://php.net/manual/en/language.constants.predefined.php


Comments
func_get_args() normally
func_get_args() normally doesn't work inside another function call. If it is, php's being gracious to you; usually I see a fatal error.
Anyway, this is a VERY handy way to debug, because you can see if additional arguments are being passed into functions from other modules as well.
Strange, I have never seen
Strange, I have never seen this before. On all the machines that I have used I have never had problems like this.
You can pass function as
You can pass function as parameter in PHP5.3+
use debug_backtrace()
Even better is dpm(debug_backtrace()); which will give you the full call stack including parameters for not only the current function but all functions that called it, which can help trace where the problem comes from.
Ah yes I forgot about that.
Ah yes I forgot about that. However when using dpm() you need to be sparing and make sure that it is not called again and again or you will definitely run out of memory.
If using devel, then use
If using devel, then use devel properly - ddebug_backtrace()
Great info here
I'm a great fan of devel and dpm... func_get_args will save me some time! Thanks!