This is a question for PHP v5.0.4.
How do you dynamically create private variables without predeclaring them as private in a class?
The reason I want to do this is because I do not know what variables I am going to need to create. [tt]$array[/tt] can be changed to nearly everything.
---------------------------------------
How do you dynamically create private variables without predeclaring them as private in a class?
Code:
final class Dynamic
{
private $sample1;
public function __construct ( )
{
$array = (
"sample2",
"sample3",
"sample4",
"sample5",
"sample6",
"sample7",
"sample8",
"sample9",
"sample10",
);
// Here's just some code that would make sense
// but not necessarily work.
foreach ( $array as $new_var )
{
private $this->$new_var = "";
}
}
}
The reason I want to do this is because I do not know what variables I am going to need to create. [tt]$array[/tt] can be changed to nearly everything.
---------------------------------------