When backward is forward
Posted: Fri Aug 29, 2003 3:29 pm
Ok ... I have a bit of code here which mysteriously enough, works. Not that I'm accustomed to writing code that doesn't ... this is just a bit counterintuitive. Here it is:
It is from a class, and is called with the constructor, after data validation. It works like extract(), excepts it creates class properties instead of locally scoped variables (ie., $this->myVar instead of $myVar.)
I know that it works, but I'm missing a piece or two from the puzzle of why it works. I have a hunch that it has to do with references and the way class variables work, but I'm unsure of that. Anyone have any clues?
Code: Select all
<?php
$revPOST = array_flip($_POST);
foreach ($revPOST as $key=>$value) {
$this->$value = $_POST[$value];
}
?>I know that it works, but I'm missing a piece or two from the puzzle of why it works. I have a hunch that it has to do with references and the way class variables work, but I'm unsure of that. Anyone have any clues?