tags:

views:

19

answers:

1

I want to make a class that has all the values of an array as a static object in that class. For example:

$vars=array(... );//some array with actual values
$Class_code='class MyClass{';

for($i=0; $i<count($vars); $i++){
    $Class_code.='static public $'.strval($vars[i]).';';
    }
eval($Class_code.'}');
/* When I echo the line above it says that the vars
for MyClass (MyClass::vars) are missing even with strval().
*/

So, how can I get $vars[i] to be a string if strval didn't work?

+2  A: 

There is a $ missing in front of i in

$vars[i]
codaddict
just to be clear, it should be $vars[$i]
sobedai