Jump to content

Getting a Functions argumentc/variable names


johanna

Recommended Posts

Hi,

 

I am looking to get the default arguments in a user function.

 

I know that you can use get_defined_functions() to get all the functions, and I know that you can also get the arguments within the function, with func_get_args().

 

But is it possible to get the argument variable names (or keys) before calling the function?

 

Here is what I need. Say I have a function with args:

 

function foo($something, $another=''){

return $something.$another;

}

 

Is there a way to get the variable/arg names, "$something" and "$another" from the functions?

 

For you c programmers, I am looking for something like inspect.getargspec() but that is for PHP

 

 

Link to comment
Share on other sites

I do not think it is possible, but what would be the point of the function to just return the arguments names?

 

I mean if that function is what you want this would work...

 

function foo($something, $another=''){
return '$something' . '$another';
}

 

But I think you want it for existing functions, I really do not think it is possible. If it is you will find it somewhere in here: http://us.php.net/manual/en/ref.funchand.php

Link to comment
Share on other sites

Thanks for the reply.

 

I am pretty familiar with all the those functions ... and it's not really what I am looking for, but rather like inspect.getargspec() in C.

 

We have a program that was developed by a programmer who ioncubed portions of it before abandoning the project, without our knowledge or consent. We are perusing court action, but it's a long process.

 

In the meantime we need to build some additional functionality quite urgently.

 

Using get_defined_functions() we are able to get the function names, we can do the same for classes.

 

But we can't figure out the arguments.

 

If anyone knows anyway to do this, I would greatly appreciate any pointers.

Link to comment
Share on other sites

 

No, he doesn't want to just get random argument values. He wants to get the argument names of each function. So in this function

 

function foo($passed, $in) {
         return "I was passed in";
}

 

It would return him $passed and $in.

 

Now I do not think there is any current functionality in php. But if you know C you may be able to create your own extension dll for just this, I would check out the core hacking section. I think you are at a loss to create your own functionality.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.