Can Live Templates grab all the variables in a php function?

Hi,

I'm wanting to have a quick way to logDebugHide all the parameters passed in to a function. Currently I'm using a macro that goes up two lines, copies that line, does a preg_match to find all the parameters, and logdebugs all the parameters using a loop.

For example, if I had the following code:

function myfunc($param1,$param2,$param3)
{

If I put my cursor right after the 3rd line (the line after the bracket), it would print out the following:


preg_match('/\$[_a-zA-Z1-9]*/','function myfunc($param1,$param2,$param3)',$matches);
 foreach($matches as $match)
 {
     $var_name = str_replace('$','',$match);
     logDebugHide($$var_name,"$match");
 }



It's an imperfect solution because:
1. It messes up if a parameter has a default value. (i.e. myfunc($param1 = "hi"))
2. It takes a couple seconds for all these lines to print out and I'd rather it just be automatic.

Is there a way to do this in Live Templates?

PhpStorm Version: 3.0.2
(I'm on a Mac)

Thanks,
Anneliese
4 comments
Comment actions Permalink

Sorry maybe I am misunderstanding you but I dont think live templates are used for debugging they are typically used as code snippets

0
Comment actions Permalink

use func_num_args(),func_get_arg(), and func_get_args() to reach arguments from your snippet?

0
Comment actions Permalink

Yeah, that's the best thing I've found so far too. The problem is that you can't also get the names of the variables to logdebug them. The function get_defined_vars() will actually give you an array with the names of variables as the keys and the values as the values, which is useful. But it also grabs all global variables if you have any. Thanks for your help!

0
Comment actions Permalink

Thanks, I know it's supposed to be for code snippets. It's just that I need to logdebughide all the parameters in a function so often that I want to make it a code snippet.

0

Please sign in to leave a comment.