tags:

views:

25

answers:

2

Hi,

I have the two following files:

main.php

include("functions.php")  
__EXTRACT();  
echo $testvar;

functions.php

function __EXTRACT(){
extract($_POST, EXTR_SKIP);
}

However, having a form with a textbox called testvar I can't get the extract function to extract the data.. if I remove the function call and insert it the extract statement directly into main.php it works. The include is not a problem as other functions in it works. Any ideas?

Cheers

+2  A: 

You can't do that: in your case extract() creates variables inside the __EXTRACT() function, when the function ends those variables are gone.

Anyway using extract() is very rarely a good idea.

kemp
Thanks, but is there any way to do it, so it would create the variable outside the function?
samuelf
Use `extract()` directly or, better, use values from `$_POST` without extracting them.
kemp
Hehe, I know that $_POST usage is the best, but this is for rapid prototyping, just wanted to know if it was possible. Thanks again.
samuelf
A: 

You don't want to do this. This is basically just emulating register_globals inside of PHP. There's a reason it has been off by default for years, and is being removed in 6...

ircmaxell