(no title)
yeahbutbut | 11 years ago
Ghetto templating (using a PHP file as a template). Extract an object from the database into local vars to echo in the "template".
Parsing fixed width files, zip the columns with their names, then extract in the processing function.
In both cases you know exactly which vars are being replaced. The real WTF is extract on $_{REQUEST,GET,POST,SERVER,...}.
ojilles|11 years ago
yeahbutbut|11 years ago
Encrypted and signed files sent over the wire from a company we do business with. Additionally I was just pairing the values up with local names that I chose (the fixed width file had no column names itself, they sent us a word doc (ugh)). And the function that called extract had exactly one local, the array I built representing a row from the file (unused after the initial call to extract).
Extract also lets you prefix the extracted vars, avoid overwriting name collisions, etc. http://php.net/extract
The code from this article is unsafe because it directly operates on user input, was not explicit about what values were required (you can filter an array by key easily enough...) and doesn't isolate the environment it's extracting in. That's the unsafe behavior.