1

is there any way to get list of variables that were defined in function, or list of all accessible variables in a function?

5
  • 1
    for what purpose? documentation? Commented Oct 22, 2010 at 10:01
  • get_defined_vars(); But it returns an array of all defined variables not specific to a function. Commented Oct 22, 2010 at 10:04
  • @Asif nope, it should work fine if called within the function Commented Oct 22, 2010 at 10:07
  • Yes, Later realized the same. Commented Oct 22, 2010 at 10:08
  • i just include files within a function and i need to make variables defined there global, this is not great decision, but there is no better solution for now Commented Oct 22, 2010 at 10:21

3 Answers 3

5

There is get_defined_vars():

This function returns a multidimensional array containing a list of all defined variables, be them environment, server or user-defined variables, within the scope that get_defined_vars() is called.

it has to be called within each function you want to analyze, though.

Sign up to request clarification or add additional context in comments.

1 Comment

thanks, im an idiot, just read the manual for that function before posting question, but couldnt test it normally because of mistake in code
2

http://php.net/manual/en/function.get-defined-vars.php

Documentation indeed ^^

Comments

0

func_num_args — Returns the number of arguments passed to the function func_get_arg — Return an item from the argument list func_get_args — Returns an array comprising a function's argument list

1 Comment

thanks, but i needed vars defined in the function, not that are passed to func

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.